我正在嘗試使用 Tkinter root.after() 方法進行無限回圈。理想情況下,應該每秒呼叫一次回圈函式。但是 after 的第二個引數中的函式只被呼叫一次。我是否遺漏了一些關于 .after 的內容,或者是 .after 開始的錯誤方法?
import tkinter as tk
root=tk.Tk()
def loop():
print("hello World")
root.after(1000, loop)
root.mainloop()
此代碼僅列印一次“hello World”,而不是每秒列印一次所需的呼叫
uj5u.com熱心網友回復:
import tkinter as tk
root=tk.Tk()
def loop():
print("hello World")
# once 'loop()' is called from root, it will get called again here
after(1000, loop)
root.after(1000, loop) # initial call to start 'loop()'
root.mainloop()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/462684.html
