(n00b) Tkinter trouble

Jason Swails jason.swails at gmail.com
Sun Nov 13 13:27:05 EST 2011


Hello,

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.

This is the approach I'm trying:

#!/usr/bin/env python

from Tkinter import *

class ActionButton(Button):
   def __init__(self, frame, text):
      self.frame = frame
      Button.__init__(self, master=self.frame, text=text,
command=self.execute)
   def execute(self):
      window = Toplevel()
      new_button = ActionButton(window, '2nd level button')
      quit_button = Button(window, text='Quit!', command=window.destroy)
      window.buttons = [new_button, quit_button]
      for button in window.buttons: button.pack()
      # Deactivate buttons from containing shell
      for button in self.frame.buttons: button.config(state=DISABLED)
      window.mainloop()
      for button in self.frame.buttons: button.config(state=ACTIVE)


top = Tk()
top_button = ActionButton(top, 'Button on top!')
top_button.pack()
quit_button = Button(top, text='Quit', command=top.destroy)
quit_button.pack()

top.buttons = [top_button, quit_button]

top.mainloop()

I'm really kind of running around in the dark here, so any advice or
explanation is appreciated.

Thanks!
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111113/c41d2771/attachment.html>


More information about the Python-list mailing list