Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The creation of your dynamic number of check buttons doesn't (and shouldn't) assign them as attributes of the instance. What you are doing is simply leaving the last one created as member attributes, which is pretty pointless.</p> <p>Also, you almost have the correct idea with your list of widgets...</p> <pre><code>class Display_Window(): def __init__(self, parent): ...snip... self.widgets = {} for i, eventDict in enumerate(self.eventNameList): eventName = eventDict['event_name'] var1 = IntVar() cbEvent = Checkbutton(self.myContainer, text=eventName, variable=var1) cbEvent.grid(row = i+2, column = 0, sticky = W) cbEvent.deselect() self.widgets[eventName] = (cbEvent, var1) self.bSelect = Button(self.myContainer, text="Select", width=10) self.bSelect.bind("&lt;Button-1&gt;", self.select) self.bSelect.bind("&lt;Return&gt;", self.select) self.bSelect.grid(row = 1, column = 2) def select(self, *args): for widget, intvar in self.widgets.iteritems(): # do stuff </code></pre> <p>What you could do, as in my example above, is store the check buttons in a dict, assuming that the event names are unique. This would make them easy to look up by name instead of looping over a list. And in that dict, I am storing a tuple, where the first item is the widget, and the second is the IntVar. I am not sure how you really wanted to organize it, but that is one way to save those references.</p> <p>Also, it seems you no longer need to do a custom lambda for the callback of the button to pass the reference, since <code>select</code> is a member of the same class, It can simply look at the <code>self.widgets</code> dict.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload