Tkinter: Dynamic entry widget

A

Arne

Hello !

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.

How can I do this?

Arne
 
F

Fredrik Lundh

Arne said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top