468,294 Members | 1,803 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,294 developers. It's quick & easy.

array of Tkinter variables?

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
1 7902


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.

Similar topics

2 posts views Thread by Marcus Schneider | last post: by
5 posts views Thread by max(01)* | last post: by
3 posts views Thread by Jim Anderson | last post: by
11 posts views Thread by William Gill | last post: by
3 posts views Thread by William Gill | last post: by
5 posts views Thread by H J van Rooyen | last post: by
4 posts views Thread by Kevin Walzer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.