python tkinter 关闭窗口 |
您所在的位置:网站首页 › dialog打开的窗口怎么关闭 › python tkinter 关闭窗口 |
您应该destroy()用来关闭tkinter窗口。 from Tkinter import * root = Tk() Button(root, text="Quit", command=root.destroy).pack() root.mainloop() 说明: root.quit() 上面的行只是绕过了root.mainloop()ie root.mainloop(),如果quit()执行了命令,ie 仍将在后台运行。 root.destroy() 当destroy()命令消失时,root.mainloop()即root.mainloop()停止。 因此,您只想退出该程序,就应该使用root.destroy()它,因为它会停止mainloop()。 但是如果你想运行无限循环并且你不想破坏你的Tk窗口并且想root.mainloop()在行之后执行一些代码,那么你应该使用root.quit()。例如: from Tkinter import * def quit(): global root root.quit() root = Tk() while True: Button(root, text="Quit", command=quit).pack() root.mainloop() #do something |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |