Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tkinter: Dynamic entry widget

Reply
Thread Tools

Tkinter: Dynamic entry widget

 
 
Arne
Guest
Posts: n/a
 
      04-25-2006
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


 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      04-25-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>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Tkinter.event.widget: handler gets name instead of widget. Terry Reedy Python 15 07-16-2012 10:32 AM
Re: Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch Python 0 07-09-2012 08:39 PM
Tkinter.event.widget: handler gets name instead of widget. Frederic Rentsch Python 0 07-08-2012 09:19 PM
user interface widget: ordered selection list: do any UI library has this widget? zhangweiwu@realss.com Javascript 0 10-10-2006 01:02 AM
I need a little help with Tkinter Entry widget Phil Schmidt Python 3 09-06-2003 07:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57