Entry Fields in a row : TextField Entry « GUI Tk « Python






Entry Fields in a row

Entry Fields in a row
 
from Tkinter import *

fields = 'First Name', 'Last Name', 'Job'

def fetch(entries):
    for entry in entries:
        print 'Input => "%s"' % entry.get()

def makeform(root, fields):
    entries = []
    for field in fields:
        row = Frame(root)                  
        lab = Label(row, width=5, text=field)
        ent = Entry(row)
        row.pack(side=TOP, fill=X)           
        lab.pack(side=LEFT)
        ent.pack(side=RIGHT, expand=YES, fill=X)
        entries.append(ent)
    return entries

def show(entries):
    fetch(entries)
    popup.destroy()

def ask():
    global popup
    popup = Toplevel()
    ents = makeform(popup, fields)
    Button(popup, text='OK', command=(lambda e=ents: show(e)) ).pack()
    popup.grab_set()
    popup.focus_set()
    popup.wait_window()

root = Tk()
Button(root, text='Dialog', command=ask).pack()
root.mainloop()



           
         
  








Related examples in the same category

1.Entry (Text field) with a label inside a border panelEntry (Text field) with a label inside a border panel
2.Use EntryUse Entry
3.Entry: TextField: get entered valueEntry: TextField: get entered value
4.Entry: enter eventEntry: enter event
5.Use Entry widgets directly and layout by rowsUse Entry widgets directly and layout by rows
6.Get value from EntryGet value from Entry
7.Set textvariable for Entry
8.Bind enter key to Entry
9.implement a very simple calculator, just evaluating Python math
10.Attached variables
11.Entry Field in a model dialogEntry Field in a model dialog