Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter after()只执行一次_Python_User Interface_Tkinter - Fatal编程技术网

Python Tkinter after()只执行一次

Python Tkinter after()只执行一次,python,user-interface,tkinter,Python,User Interface,Tkinter,一些看起来应该如此简单的事情给了我一个相当大的问题。我有一个Tkinter GUI,我正在定期更新它。具体来说,我从画布上删除项目并替换它们。作为一个例子,我只是想打印一条语句,证明after函数工作正常。当我放置一个按钮并单击它时,效果非常好,但我希望使用after()函数自动完成。不过,要让它发挥作用,我运气不太好 class app(): def __init__(self, frame): self.pad = tk.Canvas(frame) s

一些看起来应该如此简单的事情给了我一个相当大的问题。我有一个Tkinter GUI,我正在定期更新它。具体来说,我从画布上删除项目并替换它们。作为一个例子,我只是想打印一条语句,证明after函数工作正常。当我放置一个按钮并单击它时,效果非常好,但我希望使用after()函数自动完成。不过,要让它发挥作用,我运气不太好

class app():
    def __init__(self, frame):
        self.pad = tk.Canvas(frame)
        self.pad.create_window(10, 10, window=tk.Button(self.pad,command=update)
        self.pack(fill="both")

        #More Stuff

        #Neither one worked
        frame.after(1000,update)
        #self.pad.after(1000,update)

    def update(self):
        print "Updating"
        #More Stuff

if __name__=="__main__":
    root = tk.TK()
    app(root)
    root.mainLoop()

当然,这不是完整的代码,但希望它有足够的意义来了解我正在尝试做什么。因此,当我点击按钮时,我看到“更新”字样出现。但是当我使用after函数时,它在开始时出现一次,以后不再出现。我也在使用Python 2.4.4版,不要认为我没有发言权,哈哈。谢谢你的帮助

更新
的末尾之后调用

def __init__(self, frame):       
    self.frame = frame
    ...
    self.frame.after(1000, self.update)

def update(self): 
    ...
    self.frame.after(1000, self.update)
这就是工作方式。它只对回调(例如,
self.update
)进行一次排队。Per:

对该方法的每次调用只调用一次回调。到 继续调用回调,您需要在内部重新注册回调 本身


这是有道理的!我知道这很简单!谢谢你的帮助!