简体   繁体   English

Python 3没有提供干净的退出

[英]Python 3 does not give a clean exit

This code does not give a clean exit when the Exit button is clicked. 单击“退出”按钮时,此代码不会提供干净的退出。 Instead, it hangs, leaaving the dead GUI. 相反,它挂起,离开了死亡的GUI。 Hw can we fix this? 我们可以解决这个问题吗? A similar program in Python 2 behaves nicely. Python 2中的类似程序表现得很好。

from tkinter import *

import sys

root=Tk()
def quit():
    sys.exit("quitting")

frame=Frame()
frame.pack()

x=Label(root,text='Label')
x.pack()

y=Button(root,text='Button')
y.pack()

z=Button(root,text='Exit',command=quit)
z.pack()

root.mainloop()
def quit():
    root.destroy()

Should work...? 应该管用...?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM