尚不清楚顶部的代码应该做什么,但是,如果只想每秒(或每秒钟)调用一个函数,则可以使用该
after方法。
因此,如果您只想使用进行操作
textOne,则可能需要执行以下操作:
...textOne = Entry(self, width=2)textOne.x = 0def increment_textOne(): textOne.x += 1 # register "increment_textOne" to be called every 1 sec self.after(1000, increment_textOne)
您可以将此函数作为您类的方法(在本例中称为
callback),您的代码将如下所示:
class Foo(frame): def __init__(self, master=None): frame.__init__(self, master) self.x = 0 self.id = self.after(1000, self.callback) def callback(self): self.x += 1 print(self.x) #You can cancel the call by doing "self.after_cancel(self.id)" self.id = self.after(1000, self.callback)gui = Foo()gui.mainloop()



