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))
def close_windows(self, number):
#.....
if number is 3:
self.toplevel_3. destroy()
self._open_3 = False
#.....
CodePudding user response:
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.