我编写了以下类以在额外窗口中生成“监控”输出。
- 遗憾的是,它不会自动向下滚动到最近的一行。怎么了?
- 因为我在使用 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!")
最佳答案
在调用 insert 之后添加语句 cls.text.see(Tkinter.END)
。
关于python - 如何在 Tkinter 消息窗口中自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/811532/