I'm writing a TkInter application using Python 2.5 and I need to find out the status of the caps lock and shift keys (either true or false). I've searched all over the net but cant find a solution.
A:
Lock
and Shift
event modifiers:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/event-modifiers.html
vartec
2009-03-20 10:08:20
A:
I googled and got one.. I am not sure whether it works for you for all keys...
http://www.java2s.com/Code/Python/Event/KeyactionFunctionKeyALtControlShift.htm
lakshmanaraj
2009-03-20 10:11:50
+1
A:
Keyboard events in Tkinter can be tricky.
I suggest you have a look at the following, in order:
- http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm
- http://infohost.nmt.edu/tcc/help/pubs/tkinter/events.html (read the whole chapter on events)
- http://www.faqts.com/knowledge_base/view.phtml/aid/4281
Here is a program that displays the value of the keycode and state event parameters. You can use this to experiment. Click in the window, then hit the keyboard.
from Tkinter import *
root = Tk()
def key(event):
print "Keycode:", event.keycode, "State:", event.state
def callback(event):
frame.focus_set()
print "clicked at", event.x, event.y
frame = Frame(root, width=100, height=100)
frame.bind("", key)
frame.bind("", callback)
frame.pack()
root.mainloop()
codeape
2009-03-20 10:16:34