Tkinter: Dynamic entry widget

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arne

    #1

    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(ro w=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


  • Fredrik Lundh

    #2
    Re: Tkinter: Dynamic entry widget

    "Arne" wrote:
    [color=blue]
    > 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(ro w=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.[/color]

    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(ro w=4+i, column=0)
    var.append(text box)

    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>



    Comment

    Working...