Tkinter Return/Enter key handling

Bob Greschke bob at passcal.nmt.edu
Wed May 18 19:33:00 EDT 2005


I have a Tkinter Text() widget in a program that the user can type stuff 
into.  Most of our keyboards have the regular keys with a "Return" key, and 
a numeric keypad with an "Enter" key.  The Return key generates events with 
"<Return>" for the keysym, and the Enter key generates events with 
"<KP_Enter>" as the keysym.  The Text() widget does a carriage 
return/linefeed when the Return key is pressed, but does nothing when the 
Enter key is pressed.  So I did a

Text.bind("<KP_Enter", Return)

with a suitable

def Return(e):
    TheText.insert(END, linesep)

But isn't there a way to handle this with some sort of keyboard remapping 
thingy??  I'm right on the edge of understanding half of what I read about 
Tkinter. :)

Thanks!

Bob





More information about the Python-list mailing list