array of Tkinter variables?

J

Jo Schambach

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 = StringVar()
self.dllAdjust.set('000')

gives me the following error:

File "./config.py", line 787, in setDefaultVals
self.dllAdjust = 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
--
Dr Joachim Schambach
The University of Texas at Austin
Department of Physics
1 University Station C1600
Austin, Texas 78712-0264, USA
Phone: (512) 471-1303; FAX: (814) 295-5111
e-mail: (e-mail address removed)
 
L

Larry Bates

Jo said:
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 = StringVar()
self.dllAdjust.set('000')

gives me the following error:

File "./config.py", line 787, in setDefaultVals
self.dllAdjust = 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top