对Tk对象使用after方法:
from tkinter import *
root = Tk()
def task():
print("hello")
root.after(2000, task) # reschedule event in 2 seconds
root.after(2000, task)
root.mainloop()
这里是after方法的声明和文档:
def after(self, ms, func=None, *args):
"""Call function once after given time.
MS specifies the time in milliseconds. FUNC gives the
function which shall be called. Additional parameters
are given as parameters to the function call. Return
identifier to cancel scheduling with after_cancel."""
本文介绍如何使用Python的Tkinter库中的after方法来设置GUI应用程序中的定时任务。after方法允许开发者在指定的时间间隔后调用一个函数。
3500

被折叠的 条评论
为什么被折叠?



