Bind Return Key

Simon Brunning SBrunning at trisystems.co.uk
Thu Apr 26 04:14:32 EDT 2001


> From:	ps54713 [SMTP:ps54713 at swt.edu]
> I have a log on page where the user enters the username and password. It
> has an "OK" button which will allow the user to login once he clicks on
> it.
> But i also need to allow the user to use the return key from the
> keyboard instead of hitting the "OK" button
> Can anybody suggest how to bind the return key.
 
Are you using Tkinter? If so, then you are probably creating your 'OK'
button something like this:

OKButton = Button(commandFrame, text='OK', command=OKButtonClick)

With 'OKButtonClick' referring to the function that you want invoked when
the user clicks the OK button. If you want the return key to do the same
thing, you want to bind the '<Return>' event to the same function, which
will look something like this:

root.bind('<Return>', OKButtonClick)

In the above, I have bond this event for a widget called 'root' - you'll
need to experiment to find out which widget you need to bind it for.

See
<http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.
htm> for an explanation of this from someone who knows whereof he speaks.

HTH.

Whereof-one-cannot-speak-thereof-one-must-be-silent-ly y'rs,
Simon B.




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list