【发布时间】:2011-08-29 21:20:44
【问题描述】:
当单击退出按钮时,此代码不会给出干净的退出。相反,它挂起,留下死掉的 GUI。我们怎么能解决这个问题? 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()
【问题讨论】:
-
您知道,quit 是内置的。我会选择一个不同的名称(例如quit_gui)。
-
这是在学生的windoze盒子上运行的。它在我运行 Ubuntu 10.10 的 T60p 上运行良好。我将把下面的建议转达给他。
-
我也不会
from tkinter import *,因为那只会弄乱 Python 的全局命名空间。
标签: python user-interface python-3.x tkinter