[Tutor] Misunderstanding the Entry Widget

Kent Johnson kent37 at tds.net
Fri Mar 6 12:36:35 CET 2009


On Thu, Mar 5, 2009 at 10:52 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Apparently Entry does not have a callback. It seems as though it should. If
> one enters data into it and presses Return, then it would be good to know
> what the data is, so it can be used elsewhere. However, that's not the way
> it works. One seems to need a button or some other widget to make it
> happen*. So what's the game with it?

You can bind a <Return> event to an Entry widget. Here is a simple example:

from Tkinter import *

def showText(evt):
    print 'Text is:', text.get('0.0', END)
    return 'break'  # Prevent the event from propagating to the Text widget

root = Tk()
text = Text()

# This line binds the showText handler to the <Return> key event
text.bind('<Return>', showText)
text.pack()
root.mainloop()

Kent


More information about the Tutor mailing list