array of Tkinter variables?
Larry Bates
larry.bates at websafe.com
Tue Nov 1 17:40:29 EST 2005
Jo Schambach wrote:
> I want to build an array of entry widgets in python with Tkinter that
> all have similar textvariables. I was hoping that I could use an array
> of StringVar variables to attach to these widgets, so that I can loop
> through the widget creation. But my simple minded approach failed:
>
> for i in range(32):
> self.dllAdjust[i] = StringVar()
> self.dllAdjust[i].set('000')
>
> gives me the following error:
>
> File "./config.py", line 787, in setDefaultVals
> self.dllAdjust[i] = StringVar()
> AttributeError: Configurator instance has no attribute 'dllAdjust'
>
>
> ("Configurator" is the class in which this code fragment appears)
>
> How does one define an array of StringVar? If that is not possible, what
> would be an alternative approach to the idea in the code fragment above?
>
> Jo
I think what you want is something like:
self.dllAdjust=[]
for i in range(32):
sv=StringVar()
sv.set('000')
self.dllAdjust.append(sv)
(not tested)
Larry Bates
More information about the Python-list
mailing list