我有一段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 秒钟,然后关闭窗口。谢谢!
看看after
方法。例如。:
widget.after(5000,callback)
你不应该在 GUI(的主线程)中使用 sleep ——整个事情将会冻结。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)