python3的一个简单示例:
#!python3import tkinter as tkimport timeclass Splash(tk.Toplevel): def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title("Splash") ## required to make window show before the program gets to the mainloop self.update()class App(tk.Tk): def __init__(self): tk.Tk.__init__(self) self.withdraw() splash = Splash(self) ## setup stuff goes here self.title("Main Window") ## simulate a delay while loading time.sleep(6) ## finished loading so destroy splash splash.destroy() ## show window again self.deiconify()if __name__ == "__main__": app = App() app.mainloop()这样的事情在tkinter中很难实现的原因之一是,仅在程序未运行特定功能且到达主循环时才更新Windows。对于类似这样的简单操作,您可以使用
update或
update_idletasks命令使其显示/更新,但是,如果延迟时间过长,则在Windows上,窗口可能会“无响应”
解决此问题的一种方法是在整个加载例程中放置多个
update或
update_idletasks命令,或者使用线程。
但是,如果您使用线程,我建议不要将启动程序放入其自己的线程中(可能更容易实现),最好将加载任务放入其自己的线程中,并保持工作线程和GUI线程分开,因为这样容易提供更流畅的用户体验。



