I just want to close/destroy an overriden TopLevel widget when the main close button ('X' button) is clicked. The overriden TopLevel widget is not created from the root of tKinter, but from a frame.
class MyToplevel(Tki.Toplevel):
def __init__(self, parent, *args, **kwargs): # parent is not the root of tKinter, it's a frame
super().__init__(*args, **kwargs)
self.protocol("WM_DELETE_WINDOW", self.on_closing) # Not working
self.wm_protocol("WM_DELETE_WINDOW", self.on_closing) # Not working
def on_closing(self):
# The key is, how can I call this method when main close button is clicked?
self.destroy()
I also have tried self.winfo_ismapped()
and self.winfo_exists()
, but when I click in the close button, nothing happens, because the main window exists.