【问题标题】:Python 3 does not give a clean exitPython 3 没有给出干净的退出
【发布时间】: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


【解决方案1】:
def quit():
    root.destroy()

应该工作...?

【讨论】:

    猜你喜欢
    • 2021-11-23
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 2013-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    相关资源
    最近更新 更多