Tkinter: Dynamic entry widget

Discussion in 'Python' started by Arne, Apr 25, 2006.

  1. Arne

    Arne Guest

    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
     
    Arne, Apr 25, 2006
    #1
    1. Advertising

  2. "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>
     
    Fredrik Lundh, Apr 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Schmidt
    Replies:
    3
    Views:
    576
    Michael Peuser
    Sep 6, 2003
  2. =?ISO-8859-1?Q?Otto_Kr=FCse?=

    limiting text input in Tkinter Entry widget

    =?ISO-8859-1?Q?Otto_Kr=FCse?=, Feb 22, 2004, in forum: Python
    Replies:
    5
    Views:
    3,297
    Peter Otten
    Feb 23, 2004
  3. Frederic Rentsch
    Replies:
    0
    Views:
    258
    Frederic Rentsch
    Jul 8, 2012
  4. Terry Reedy
    Replies:
    15
    Views:
    647
    Frederic Rentsch
    Jul 16, 2012
  5. Frederic Rentsch
    Replies:
    0
    Views:
    444
    Frederic Rentsch
    Jul 9, 2012
Loading...

Share This Page