我可以使用 sys.exit() 来停止 Tkinter 程序吗
Can I use sys.exit() to stop a Tkinter program
使用 sys.exit()
停止 Tkinter 程序有问题吗?
我知道人们通常使用 root.destroy()
为什么会这样?
我都用。 root.destroy() 用于销毁根 tkinter 实例中的所有 windows(父、子),但它不会结束 python 程序。
sys.exit() 停止 python 使用的所有活动应用程序。
简而言之,如果您的 python 代码专门运行一个 tkinter GUI,并且它的功能在 window 关闭后结束,那么请同时使用 root.destroy() 和 sys.exit() 有效结束会话。
当然可以,但它会终止整个程序,包括您的应用程序。
根据此处:https://www.daniweb.com/programming/software-development/threads/66698/exit-a-tkinter-gui-program。 root.destroy
是一种安全、可靠的退出 Tkinter 应用程序的方法。来自 link:
destroy() just terminates the mainloop and deletes all widgets. So it seems to be safer if you call your app from another Tkinter app, or if you have multiple mainloops.
使用 sys.exit()
停止 Tkinter 程序有问题吗?
我知道人们通常使用 root.destroy()
为什么会这样?
我都用。 root.destroy() 用于销毁根 tkinter 实例中的所有 windows(父、子),但它不会结束 python 程序。
sys.exit() 停止 python 使用的所有活动应用程序。
简而言之,如果您的 python 代码专门运行一个 tkinter GUI,并且它的功能在 window 关闭后结束,那么请同时使用 root.destroy() 和 sys.exit() 有效结束会话。
当然可以,但它会终止整个程序,包括您的应用程序。
根据此处:https://www.daniweb.com/programming/software-development/threads/66698/exit-a-tkinter-gui-program。 root.destroy
是一种安全、可靠的退出 Tkinter 应用程序的方法。来自 link:
destroy() just terminates the mainloop and deletes all widgets. So it seems to be safer if you call your app from another Tkinter app, or if you have multiple mainloops.