Close a tkinter window?

Tags: tkinter python

How do I end a Tkinter program? Let's say I have this code:

from Tkinter import *

def quit():
    # code to exit

root = Tk()
Button(root, text="Quit", command=quit).pack()

How should I define the quit function?


Try this:

from Tkinter import *
root = Tk()
Button(root, text="Quit", command=lambda:quit).pack()

Illumination in case of confusion...

def quit(self):

A) destroy() stops the mainloop and kills the window, but leaves python running

B) exit() stops the whole process

Just to clarify in case someone missed what destroy() was doing, and the OP also asked how to "end" a tkinter program.

Use root.destroy()! Works for me just fine.

This video can help you solving your question :)
By: admin