Entry: TextField: get entered value : TextField Entry « GUI Tk « Python






Entry: TextField: get entered value

Entry: TextField: get entered value
 

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)


def fetch():
    print 'Input => "%s"' % ent.get()          

root = Tk()
ent = Entry(root)
ent.insert(0, 'Type words here')               
ent.pack(side=TOP, fill=X)                     

ent.focus()                                    
ent.bind('<Return>', (lambda event: fetch()))  
btn = Button(root, text='Fetch', command=fetch) 
btn.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: enter eventEntry: enter event
4.Use Entry widgets directly and layout by rowsUse Entry widgets directly and layout by rows
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