Python Tkinter应用程序无法正常退出
问题内容:
from TKinter import *
class Ui(Frame):
def __init__(self)
Frame.__init__(self, None)
self.grid()
bquit=Button(self, text="Quit", command=self.quit_pressed)
bquit.grid(row=0, column=0)
def quit_pressed(self):
self.destroy()
app=Ui()
app.mainloop()
为什么当我按下“退出”按钮时,该Tkinter程序无法正常结束?
问题答案:
使用self.destroy()只是销毁Frame,而不是顶层容器,您需要执行self.master.destroy()才能正确退出