Tkinter: Dynamic entry widget
Fredrik Lundh
fredrik at pythonware.com
Tue Apr 25 13:24:54 EDT 2006
"Arne" wrote:
> I want to create entry widgets dynamically.
> var = ["one", "two", "three"]
> i=0
> for x in var:
> textbox = "t_", x
> textbox = entry(frame)
> textbox.grid(row=4+i, column=0)
> i = i + 1
> This works ok. On the window are the entries like I want.
>
> When I want to get to entered data from the entry widget. I am not able to
> get them.
> The statement: t_one.get()
> dosent work. I am getting an error message that t_one is not global defined.
there's no t_one variable in your program. assigning some stuff to
a variable doesn't create a variable with that name (if your python
tutorial told you that you could do that, make sure you get your
money back).
the usual way to store a list of values (widgets) is to use a list:
var = []
for x in range(3):
textbox = entry(frame)
textbox.grid(row=4+i, column=0)
var.append(textbox)
print var[0].get() # returns the content of the first textbox
print var[1].get() # same, for the second textbox
print var[2].get() # same, for the third textbox
</F>
More information about the Python-list
mailing list