views:

2251

answers:

1

How do I handle the window close event (user clicking the 'X' button) in a Python Tkinter program?

+5  A: 

Use a Tkinter protocol handler to handle window manager events:

root.protocol("WM_DELETE_WINDOW", handler)
# or toplevel.protocol(...

def handler():
    if tkMessageBox.askokcancel("Quit?", "Are you sure you want to quit?"):
        root.quit()
Matt Gregory