Python Tkinter 应用程序未正确退出

jld*_*ont 4 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()
Run Code Online (Sandbox Code Playgroud)

当我按下“退出”按钮时,为什么这个 Tkinter 程序没有正确结束?

Jua*_*mez 5

使用 self.destroy() 您只是在销毁框架,而不是顶级容器,您需要执行 self.master.destroy() 才能正确退出