steffffffff
steffffffff

Reputation: 85

How can I bind the Enter key to my tkinter window

I would like to do this for the Enter key but not the Return key:

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

If you are not clear on the difference between the enter key and the return key http://en.wikipedia.org/wiki/Enter_key

I would appreciate help, thank you!

Upvotes: 3

Views: 3209

Answers (1)

tobias_k
tobias_k

Reputation: 82889

One way to find out what's the correct key binding is to create a key binding for all keys and printing the keysym of the event. Now, just hit the key you want to bind the event to and see what it prints.

import Tkinter
root = Tkinter.Tk()
def func(event):
    print event.keysym
root.bind("<Key>", func)
root.mainloop()

When pressing the Enter key, this will print KP_Enter, so your binding should be

root.bind('<KP_Enter>', func)

Upvotes: 3

Related Questions