By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,092 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,092 IT Pros & Developers. It's quick & easy.

array of Tkinter variables?

P: n/a
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
--
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: js******@physics.utexas.edu
Nov 1 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


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
Nov 1 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.