Need help with Tkinter for dynamic # of objects

Fredrik Lundh fredrik at pythonware.com
Mon Dec 13 04:05:51 EST 1999


Donald Parker <dbparker at nortelnetworks.com> wrote:
> I'm trying to define a Frame class that can have a variable number of button
> widgets. Within the Frame class I've tried coding the constructor as
> 
> n=0
> while n < m :
>     self.set_of_buttons[n] = [Tkinter.Button(self)]
>     n+n+1

that's just plain weird ;-)

try this:

self.set_of_buttons = []

for n in range(m):
    b = Tkinter.Button(self)
    b.pack(...)
    self.set_of_buttons.append(b)

> I thought types and variables came into existence as a result of assignment,

yes, but assigning to a *member* of a collection
variable doesn't create the collection itself.

(and lists don't grow by themselves either).

</F>





More information about the Python-list mailing list