كيفية التمرير تلقائيا في غضون Tkinter نافذة الرسالة

StackOverflow https://stackoverflow.com/questions/811532

سؤال

كتبت الطبقة التالية لإنتاج "رصد" إخراج ضمن إطار إضافي.

  1. للأسف لا انتقل تلقائيا إلى أسفل إلى آخر الخط.ما هو الخطأ ؟
  2. كما أنا أيضا لدي مشاكل مع Tkinter و ipython:كيف ما يعادل التنفيذ مع qt4 تبدو وكأنها ؟

هنا هو رمز:

import Tkinter
class Monitor(object):
  @classmethod
  def write(cls, s):
    try:
      cls.text.insert(Tkinter.END, str(s) + "\n")
      cls.text.update()
    except Tkinter.TclError, e:
      print str(s)
  mw = Tkinter.Tk()
  mw.title("Message Window by my Software")
  text = Tkinter.Text(mw, width = 80, height = 10)
  text.pack()

الاستخدام:

Monitor.write("Hello World!")
هل كانت مفيدة؟

المحلول

إضافة إلى بيان cls.text.see(Tkinter.END) بعد واحد يدعو إدراج.

نصائح أخرى

إلى أولئك الذين قد ترغب في محاولة الربط:

def callback():
    text.see(END)
    text.edit_modified(0)
text.bind('<<Modified>>', callback)

فقط كن حذرا.كما @BryanOakley أشار إلى تعديل الحدث الظاهري هو إلا مرة واحدة حتى يتم إعادة تعيين.النظر في أدناه:

import Tkinter as tk

def showEnd(event):
    text.see(tk.END)
    text.edit_modified(0) #IMPORTANT - or <<Modified>> will not be called later.

if __name__ == '__main__':

    root= tk.Tk()

    text=tk.Text(root, wrap=tk.WORD, height=5)
    text.insert(tk.END, "Can\nThis\nShow\nThe\nEnd\nor\nam\nI\nmissing\nsomething")
    text.edit_modified(0) #IMPORTANT - or <<Modified>> will not be called later.
    text.pack()
    text.bind('<<Modified>>',showEnd)

    button=tk.Button(text='Show End',command = lambda : text.see(tk.END))
    button.pack()
    root.mainloop()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top