0

I am trying to execute a function with the closing event: self.toplevel_1.protocol ('WM_DELETE_WINDOW', lambda: self.close_windows (3)) but it does not execute, I have thought that it has to do with the window manager since it I have removed and I have an independent closing button, I have looked for some other closing event for windows without the window manager but I can't find it, I would like to know if there is any closing event for this case, thank you very much.

def windows_open(self):
    self.Toplevel_3 = Toplevel(self)
    #self.toplevel_3 .protocol('WM_DELETE_WINDOW',
                     lambda: self.close_windows(3))  # ancient
    self.toplevel_STUF.bind('<Destroy>',lambda e: self.close_windows(3))

def close_windows((self,  number, event=None):
    var = event.widget()
    if number is 3:
        if var is:    # How `var` gives an error, I don't know what it returns, here I stay 
            self.toplevel_3. destroy()
            self._open_3 = False
    #.....
2
  • self.toplevel_3. destroy(), why the space there? Commented Sep 28, 2021 at 15:04
  • In close_windows() function, does self.toplevel_3.quit() work instead of self.toplevel_3.destroy()? Commented Sep 29, 2021 at 4:38

1 Answer 1

1

The WM_DELETE_WINDOW protocol and other protocols are specifically related to window manager protocols. If you don't have a window manager, they don't apply.

From the protocol man page:

This command is used to manage window manager protocols...

In the absence of a window manager, you can bind to the <Destroy> event which should fire whether you have a window manager or not. You have to be careful with this if you bind to the root window. Bindings on the root widget or a Toplevel will apply to all descendant widgets, so in the bound function you'll want to run code only if event.widget refers to the root or Toplevel window.

Sign up to request clarification or add additional context in comments.

1 Comment

In addition I would share my experience that the function that is bind to destroy of the root window event shouldn't be a long run, otherwise it throws an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.