I am developing a program to control a machine that will have only a keypad connected. I am using Python 2.7
and Tkinter 8.5
. I am using OptionMenu
s to allow user to do setup on machine.
When I run under Windows I am able to use arrow keys on keypad to traverse thru drop down list, then use key pad enter to pick option. This is not working on Linux (Debian Wheezy).
How do I bind KP_Enter
to behave as return key?
import Tkinter
def c(self, event):
event.b[".keysym"] = "<<space>>"
print "button invoked"
t = Tkinter.Tk()
b = Tkinter.OptionMenu(t, ".500", ".510", ".520",
".550", ".560", ".570", ".580", command=c)
t.bind("<KP_Enter>", c)
e = Tkinter.Entry()
e.pack()
b.pack(anchor=Tkinter.E)
t.mainloop()
Yes, it was as you say: pressing the arrow (shift) + delete (NumLock) wich you can find it above of "7" button of the keypad.
To switch wasd keys and arrow keys, please presss FN + W .
With this script (from here), it should be easy to identify the key event triggered by Tkinter when you press any key, whether that is <Return>
, <KP_Enter>
, or (somehow, maybe your keypad has a funny mapping) something else.
Just look at the console output when you press the desired button, and use that key event name in your actual code.
import Tkinter
def callback(e):
print e.keysym
w = Tkinter.Frame(width=512, height=512)
w.bind("<KeyPress>", callback)
w.focus_set()
w.pack()
w.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With