0
Bind a keyboard with Button in Tkinter
Hi I would just like to know how to bind a button to a key on the keyboard (more specifically a number, I am working on making a calculator) on a GUI and I am using Tkinter. Thank you
1 Réponse
+ 2
Here is a guide (you may have to adjust the code to be python 3 compatible)
http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
You need a function that handles keypresses and you bind it to all the buttons. A single function will probably work for all the digits.
def key_pressed(e):
print("pressed", e.char)
button1.bind("<Key>", key_pressed)