root.destroy() 和 root.quit() 有什么区别? [英] What is the difference between root.destroy() and root.quit()?

查看:238
本文介绍了root.destroy() 和 root.quit() 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Python中使用tkinter,关闭根窗口时root.destroy()root.quit()有什么区别?

In Python using tkinter, what is the difference between root.destroy() and root.quit() when closing the root window?

一个比另一个更受欢迎吗?一个会释放另一个不释放的资源吗?

Is one prefered over the other? Does one release resources that the other doesn't?

推荐答案

quit() 停止 TCL 解释器.在大多数情况下,这就是您想要的,因为您的 Tkinter 应用程序也会停止.这可能是一个问题,如果你例如从空闲状态调用您的应用程序.idle 本身就是一个 Tkinker 应用程序,因此如果您在应用程序中调用 quit() 并且 TCL 解释器被终止, idle 也会终止(或混淆).

quit() stops the TCL interpreter. This is in most cases what you want, because your Tkinter-app will also stop. It can be a problem, if you e.g. call your app from idle. idle is itself a Tkinker-app, so if you call quit() in your app and the TCL interpreter gets terminated, idle will also terminate (or get confused ).

destroy() 只是终止主循环并删除所有小部件.因此,如果您从另一个 Tkinter 应用程序调用您的应用程序,或者如果您有多个主循环,则似乎更安全."

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."

取自 http://www.daniweb.com/forums/thread66698.html

这篇关于root.destroy() 和 root.quit() 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆