[Tutor] using the enter key
Michael Lange
klappnase at freenet.de
Tue Apr 5 11:55:39 CEST 2005
On Tue, 5 Apr 2005 06:28:54 +1000
"Diana Hawksworth" <dianahawks at optusnet.com.au> wrote:
> Hello list!
>
> At the moment I have some user input tied to a button that allows the input to be "submitted" and then an answer is supplied. How can I get rid of this submit button, and have the user just press the "enter" key and have the same result happen?
>
> TIA. Diana
You need to create an event handler for the Entry widget that is called each time the Enter key is pressed over the widget:
entry.bind('<Return>', submit)
where "entry" is of course your Entry widget and "submit" the function to be called.
Please note that the "enter" key's event descriptor is "'<Return>'" in Tk (there's an '<Enter>' event, too, which is when the mouse
pointer enters the widget) and that the callback gets an event instance passed, so the function definition
has to look like this:
def submit(event):
(...)
I hope this helps
Michael
More information about the Tutor
mailing list