storing variable names in a list before they are used?

John Salerno johnjsal at NOSPAMgmail.com
Sat Sep 30 12:48:43 EDT 2006


John Salerno wrote:

> (the variables would store whatever information is entered in the text 
> boxes to the right of each label. I'm doing it this way so I can write a 
> loop to construct my GUI components).

Thanks very much for the responses guys. I actually tried something 
similar with a dictionary already, but then I discovered the obvious: I 
need them in a certain order! :)

Here is what I want to do more specifically: I am creating a single 
frame (wxPython terminology for a window) and the user will be able to 
click a "New" button which will open a new tab in that frame (using the 
wx.Notebook class). Each time a new tab is opened, it will contain a 
form to fill out, with a label widget on the left ("First Name:") and a 
text box control on the right (the underlines), like this:

First Name: ________
Last Name:  ________
Job Title:  ________
etc.
etc.



In wxPython, you can use "sizers" for layout control, and in this case 
the FlexGridSizer is ideal. You just assign the above widgets to it in 
this order: first label, first textbox, second label, second textbox, etc.

Instead of manually creating these widgets and adding all of them to the 
sizer (and having to add or delete code later in case something changes) 
I wanted to use some type of for loop to do it for me. This is easy for 
creating and adding the labels, because I need no reference for them 
later. But I will need a reference for the textboxes so I can later get 
the data that is in them.

So my original question involved finding a way to assign a variable name 
to the textboxes while they are being automatically created in a for 
loop. This seems like something that is probably done quite often and 
maybe I'm just not thinking of the proper idiom that is used.

Thanks!



More information about the Python-list mailing list