Python Tkinter app does not quit properly

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()

Why doesn't this Tkinter program end properly when I click the Exit button?

+3
source share
2 answers

With self.destroy (), you simply destroy Frame, not the top-level container, you need to do self.master.destroy () so that it can exit correctly

+4
source

, , , quit_pressed. , , - , . - , , , , . - , .

def quit_pressed(self):
    self.destroy() #This destroys the current self frame, not the root frame which is a different frame entirely

, ,

def quit_pressed(self):
    quit() #This will kill the application itself, not the self frame.
+3

All Articles