Re: [Tutor] keep from opening multiple Toplevel windows
On Fri, Oct 3, 2008 at 8:31 PM, [EMAIL PROTECTED] wrote: I have a Tkinter button widget that when pressed invokes a Toplevel window call each time. The Toplevel window thus generated has a close button on it. As you might guess, when multiple Toplevel windows are open, I can press on a 'close' button to '.destroy' the window, but all other Toplevel windows remain and do not respond to their 'close' buttons. I understand why THIS happens, but... The behavior I seek is that one and only one Toplevel window gets generated no matter how many times the original Tkinter button is pressed. A new Toplevel is generated only after the previous one is closed. The way I would do this is to have the class containing the button handler save a reference to the window. When the window is closed then set the reference to None. Then the button handler can check to see if it already has a window. Alternately you could just create a single, hidden window at startup, then the button shows the window and the close box just hides it instead of destroying it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] keep from opening multiple Toplevel windows
[EMAIL PROTECTED] wrote The behavior I seek is that one and only one Toplevel window gets generated no matter how many times the original Tkinter button is pressed. Here is a minimal example of what I think you want? Does that help? -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld -- # TestTopLevel.py from Tkinter import * class MainWin(Frame): def __init__(self, parent, sub=None): Frame.__init__(self, parent) self.parent = parent Label(self, text=This is the main window).pack() self.bShow = Button(self, text=Show Sub, command = self.doShow) self.bShow.pack() self.bQuit = Button(self, text=Quit, command = self.quit) self.bQuit.pack() self.sub = sub self.pack() def doShow(self): try: self.sub.deiconify() except: self.sub = SubWindow(self.parent) self.sub.withdraw() self.sub.deiconify() class SubWindow(Toplevel): def __init__(self, parent): Toplevel.__init__(self, parent) Label(self, text=Child Window).pack() self.bClose = Button(self, text=Close, command=self.doClose) self.bClose.pack() self.withdraw() def doClose(self): self.withdraw() def main(): app = Tk() m = MainWin(app, SubWindow(app)) app.mainloop() if __name__ == __main__: main() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] keep from opening multiple Toplevel windows
I have a Tkinter button widget that when pressed invokes a Toplevel window call each time. The Toplevel window thus generated has a close button on it. As you might guess, when multiple Toplevel windows are open, I can press on a 'close' button to '.destroy' the window, but all other Toplevel windows remain and do not respond to their 'close' buttons. I understand why THIS happens, but... The behavior I seek is that one and only one Toplevel window gets generated no matter how many times the original Tkinter button is pressed. A new Toplevel is generated only after the previous one is closed. My question is: how does one check that a particular Toplevel window is open? I've tried just checking on the Toplevel widget name with try-except, but the value of the Toplevel name stays persistent even when the .destroy method is used to kill the Toplevel window, which makes try-except think the Toplevel is still open. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor