469,964 Members | 1,681 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Tkinter: Dynamic entry widget

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
Apr 25 '06 #1
1 6339
"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>

Apr 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Phil Schmidt | last post: by
6 posts views Thread by Elaine Jackson | last post: by
2 posts views Thread by uri bushey | last post: by
7 posts views Thread by Harlin Seritt | last post: by
6 posts views Thread by William Gill | last post: by
3 posts views Thread by Matt Hammond | last post: by
8 posts views Thread by Lie | last post: by
1 post views Thread by C Martin | last post: by
reply views Thread by Leonhard Vogt | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.