<font color="#000000"><br></font><br><div class="gmail_quote">On Sun, Nov 13, 2011 at 1:27 PM, Jason Swails <span dir="ltr"><<a href="mailto:jason.swails@gmail.com">jason.swails@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#000000">Hello,<br><br>I'm trying my hand at creating a Tkinter application, but not having much luck.  I'm trying to have my top level window be a series of buttons with different options on them.  Every time a button is pressed, it opens up a new window with options.  While that new window is open, all of the buttons on the original window are disabled.  However, I want all of those buttons to become active again once I quit my new window.  I can't seem to reactivate those buttons no matter what I do.<br>

<br>This is the approach I'm trying:<br><br>#!/usr/bin/env python<br><br>from Tkinter import *<br><br>class ActionButton(Button):<br>   def __init__(self, frame, text):<br>      self.frame = frame<br>      Button.__init__(self, master=self.frame, text=text, command=self.execute)<br>

   def execute(self):<br>      window = Toplevel()<br>      new_button = ActionButton(window, '2nd level button')<br>      quit_button = Button(window, text='Quit!', command=window.destroy)<br>      window.buttons = [new_button, quit_button]<br>

      for button in window.buttons: button.pack()<br>      # Deactivate buttons from containing shell<br>      for button in self.frame.buttons: button.config(state=DISABLED)<br>      window.mainloop()<br>      for button in self.frame.buttons: button.config(state=ACTIVE)<br>

<br><br>top = Tk()<br>top_button = ActionButton(top, 'Button on top!')<br>top_button.pack()<br>quit_button = Button(top, text='Quit', command=top.destroy)<br>quit_button.pack()<br><br>top.buttons = [top_button, quit_button]<br>

<br>top.mainloop()<br><br>I'm really kind of running around in the dark here, so any advice or explanation is appreciated.<br></font></blockquote><div><br>Another approach I think will work, and that I'm going to try, is to subclass Toplevel and simply assign the higher-level frame/window as an instance attribute.  Then, I can reactivate all of the buttons in the destroy() method before calling the destroy() method of Toplevel on self.  Something like this:<br>
<br>[untested]<br><br>class MyToplevel(Toplevel):<br><br>   def __init__(self, root, **options):<br>      self.root = root<br>      Toplevel.__init__(self, options)<br>      for button in self.root.buttons: button.config(state=DISABLED)<br>
   <br>   def destroy(self):<br>      for button in self.root.buttons: button.config(state=ACTIVE)<br>      Toplevel.destroy(self)<br><br>This allows me to avoid running "mainloop()" on a non-root Toplevel instance, but links the re-activation of the buttons with the destruction of the child window (which was the effect I was going for).  I must not understand what mainloop() does, fully (does it only make sense to run it on Tkinter.Tk()?)<br>
<br>Thanks!<br>Jason<br><br></div>
</div>