import tkinter
class App():
def __init__(self):
self.root = Tkinter.Tk()
button = Tkinter.Button(self.root, text = 'root quit', command=self.quit)
button.pack()
self.root.mainloop()
def quit(self):
self.root.destroy
app = App()
How can I make my quit function to close the window?
Add parentheses after
destroyto call the method.When you use
command=self.root.destroyyou pass the method toTkinter.Buttonwithout the parentheses because you wantTkinter.Buttonto store the method for future calling, not to call it immediately when the button is created.But when you define the
quitmethod, you need to callself.root.destroy()in the body of the method because by then the method has been called.