Hide the root window when a Toplevel window is opened and make it reappear when the Toplevel is destroyed

前端 未结 1 321
小鲜肉
小鲜肉 2021-01-23 18:28

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

相关标签:
1条回答
  • 2021-01-23 19:30

    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()
    
    0 讨论(0)
提交回复
热议问题