Overriding Tkinter “X” button control (the button that close the window) [duplicate]

It sounds as if your save window should be modal.

If this is a basic save window, why are you reinventing the wheel?
Tk has a tkFileDialog for this purpose.


If what you want is to override the default behaviour of destroying the window, you can simply do:

root.protocol('WM_DELETE_WINDOW', doSomething)  # root is your root window

def doSomething():
    # check if saving
    # if not:
    root.destroy()

This way, you can intercept the destroy() call when someone closes the window (by any means) and do what you like.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)