How can I hide the MAIN window when the SECOND window is opened and then make the MAIN window reappear when the SECOND window is closed?
I understand the use of withdraw
You can put a binding on <Destroy>
of the second window which will call a function that will call deiconify
on the master.
This would be easier in your code if Second
was a subclass of Toplevel
. If you did that, you could hide this code inside the definition of Second
. For example:
...
def Open(self):
second_window = Second(self.master)
...
class Second(Toplevel):
def __init__(self, master):
Toplevel.__init__(self, master)
self.master = master
self.master.withdraw()
self.bind("<Destroy>", self.on_destroy)
def on_destroy(self, event):
if event.widget == self:
self.master.deiconify()