Changing properties of a class instance widget

Mark Light light at
Tue Jun 10 14:43:02 CEST 2003

     I have a class (after some help from this newsgoup) that generates an
array of buttons that I can select and deselect via left clicks etc(done
using bind). What I would like to be able to do is to have a button that
when clicked will select all in a particular coulmn of buttons. So I need to
be able to referebce the separate instances.

A few snippets of the code!
#Class to generate sample buttons - including sample list population and
data entry
class MyButton(Button):
   def __init__(self, parent, buttonNb, **options):
     self.__buttonNb = buttonNb
     apply(Button.__init__, (self, parent), options)
     self.configure( width=10)
     self.bind('<Button-1>', self.onLeftClick)
     self.bind('<Button-2>', self.onMiddleClick)
     self.bind('<Button-3>', self.onRightClick)
     self.bind('<Double-1>', self.onDoubleClick)

   #Define middleclick
   def onMiddleClick(self, event):
     self.config(None, bg=('green'), relief=SUNKEN)
     print "MiddleClick on Sample" + `self.__buttonNb`

#generate buttons from a list (called Layout - e.g. [(frame3b2, 1),
(frame3b2, 2),....])
for frame, sample in Layout:
     b = MyButton(frame, sample, text="Sample %s" % sample)


How can I refer to a particular instance of MyButton to change it's widget

Many Thanks,


More information about the Python-list mailing list