array of Tkinter variables?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jo Schambach

    #1

    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'


    ("Configurat or" 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: jschamba@physic s.utexas.edu
  • Larry Bates

    #2
    Re: array of Tkinter variables?



    Jo Schambach wrote:[color=blue]
    > 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'
    >
    >
    > ("Configurat or" 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[/color]

    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

    Comment

    Working...