繁体   English   中英

tkinter 中的 .after() 方法只被调用一次

[英].after() method in tkinter only gets called once

我正在尝试使用 Tkinter root.after() 方法进行无限循环。 理想情况下,应该每秒调用循环 function。 但是 after 的第二个参数中的 function 只被调用了一次。 我是否遗漏了一些关于.after 或 is.after 的错误方法?

import tkinter as tk
root=tk.Tk()
def loop():
  print("hello World")
root.after(1000, loop)
root.mainloop()

此代码仅打印一次“hello World”,而不是每秒打印一次所需的调用

import tkinter as tk
root=tk.Tk()


def loop():
    print("hello World")
    # once 'loop()' is called from root, it will get called again here
    root.after(1000, loop)


root.after(1000, loop)  # initial call to start 'loop()'
root.mainloop()

暂无
暂无

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

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