Python 如何使tkinter窗口在延迟几秒钟后自动关闭?
我有一个tkinter窗口,Python 如何使tkinter窗口在延迟几秒钟后自动关闭?,python,tkinter,wait,Python,Tkinter,Wait,我有一个tkinter窗口,root,它应该在几秒钟延迟后关闭。以下是我当前窗口的代码: from tkinter import * root=Tk() def WaitAndClose(): global root #close root after a few seconds Button(root, text='Close', command=WaitAndClose).pack() mainloop() 编辑:root。在(,)之后是有效的命令。以下命令应在5000毫秒
root
,它应该在几秒钟延迟后关闭。以下是我当前窗口的代码:
from tkinter import *
root=Tk()
def WaitAndClose():
global root
#close root after a few seconds
Button(root, text='Close', command=WaitAndClose).pack()
mainloop()
编辑:root。在(,)之后是有效的命令。以下命令应在5000毫秒(5秒)后关闭tkinter窗口
root
(根据需要进行更改):
以下操作应在5000毫秒(5秒)后关闭tkinter窗口
root
(根据需要进行更改):
阅读每个小部件上可用的
after
和destroy
方法。@Azxdrewa查看我的答案,了解应该工作的实现阅读每个小部件上可用的after
和destroy
方法。@Azxdrewa查看我的答案,了解应该工作的实现
root.after(5000, root.destroy)