Need help with Tkinter for dynamic # of objects
Doug Hellmann
doughellmann at home.com
Mon Dec 13 07:35:05 EST 1999
It looks like you are trying to use a list to store the buttons after
they are created. You need to create a list before you can insert
anything into it. Try this:
self.set_of_buttons = []
for n in range(m):
self.set_of_buttons.append(Tkinter.Button(self))
Doug
Donald Parker wrote:
>
> Apologies in advance .... I'm quite new to Python so I suspect my problem is
> quite simple and due to a basic misunderstanding ... nevertheless, some
> insight into that misunderstanding would be appreciated.
>
> 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
>
> ...which results an exception for an attribute error for 'set_of_buttons'
>
> I thought types and variables came into existence as a result of assignment,
> but I am clearly breaking a rule I do not understand here.
>
> I would like to know:
> a) what rule I am breaking
> b) how to achieve my objective
More information about the Python-list
mailing list