好的,我想组装一个 Python/Tkinter 对话框,它显示一条简单的消息并在 N 秒后自毁。有没有简单的方法可以做到这一点?
最佳答案
您可以使用 after
函数在延迟结束后调用函数,并使用 destroy
关闭窗口。
举个例子
from Tkinter import Label, Tk
root = Tk()
prompt = 'hello'
label1 = Label(root, text=prompt, width=len(prompt))
label1.pack()
def close_after_2s():
root.destroy()
root.after(2000, close_after_2s)
root.mainloop()
更新:之后的文档字符串说:
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 - 如何启动自毁的 Python/Tkinter 对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1917198/