关闭一个tkinter窗口经过一段时间之后

2024-10-01 07:10:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一段Python代码,它应该在一段时间内打开一个新窗口,然后关闭该窗口。单击按钮可触发窗口。这是我的基本知识。在

def restore(self):
    self.restore = Toplevel()

    message = "Select an available Backup to Restore to."

    Label(self.restore, text=message).pack()
    # We then create and entry widget, pack it and then
    # create two more button widgets as children to the frame.

    os.chdir('.')
    for name in os.listdir("."): 
        if os.path.isdir(name):
            self.button = Button(self.restore, text=name,command=self.restoreCallBack)
            self.button.pack(side=BOTTOM,padx=10)

def restoreCallBack(self):
    self.restoreCB = Toplevel()

    message = "Please wait while the database is restored..."
    Label(self.restoreCB, text=message, padx=100, pady=20).pack()

    time.sleep(5)

    self.restore.destroy()
    self.restoreCB.destroy()

我需要restoreCallBack窗口显示5秒钟,然后关闭窗口。谢谢!在


Tags: totextnameselfmessageosdefbutton
1条回答
网友
1楼 · 发布于 2024-10-01 07:10:27

看看after方法。e、 g.:

widget.after(5000,callback)

你不应该在GUI中使用sleep(主线程),整个事情都会冻结。在

相关问题 更多 >