繁体   English   中英

实时更新Tkinter Text小部件?

[英]Update a Tkinter Text widget real time?

from Tkinter import *

class Output:
    def __init__(self,master):
    self.u=Text(master,width=40)
    self.u.grid(row=0,column=0)
    self.v=Button(master,text="Add text",command="Write")
    self.v.grid(row=1,column=0)

def Write(self):
    self.u.insert(1.0,"Meh")

root=Tk()
output=Output(root)
root.mainloop()

如何使按钮实时工作? 如果可能的话,我想解释为什么这不起作用。

我不明白你的“实时工作”是什么意思,但我肯定会在你的代码中看到一个错误。 command选项接受command的引用,但是你给它一个字符串。 将按钮定义更改为:

self.v = Button(master, text="Add text", command=Write)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM