Use Entry widgets directly and layout by rows : TextField Entry « GUI Tk « Python






Use Entry widgets directly and layout by rows

Use Entry widgets directly and layout by rows
 
from Tkinter import *

from tkMessageBox import askokcancel          

class Quitter(Frame):                         
    def __init__(self, parent=None):          
        Frame.__init__(self, parent)
        self.pack()
        widget = Button(self, text='Quit', command=self.quit)
        widget.pack(expand=YES, fill=BOTH, side=LEFT)
    def quit(self):
        ans = askokcancel('Verify exit', "Really quit?")
        if ans: Frame.quit(self)


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

if __name__ == '__main__':
    root = Tk()
    ents = makeform(root, fields)
    root.bind('<Return>', (lambda event, e=ents: fetch(e)))   
    Button(root, text='Fetch',
                 command=(lambda e=ents: fetch(e))).pack(side=LEFT)
    Quitter(root).pack(side=RIGHT)
    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.Entry Fields in a rowEntry Fields in a row
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