[Tutor] Lots of variables

Alan G alan.gauld at freenet.co.uk
Sun Aug 7 19:04:13 CEST 2005


> I am trying to write a gui that has a lot of checkboxes. It is over 
> 200
> different ones. I use a for statement to generate:
>
>        ver = 200
>        for i in ['Car','House','Boat','Plane']:
>            self.fra26_che01p = Checkbutton (self.fra26)
>            self.fra26_che01p.place(in_=self.fra26,x=5,y=ver)
>            self.fra26_che01p.configure(text=i)

> The variable does not work for obvious reasons. I need to change 
> variable
> for each new creation. If I had made the variables manually, I would 
> have

Try a dictionary using the strings in your list as the keys and the
controls as the values.

See the bank account example in my OOP topic for an example.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 



More information about the Tutor mailing list