tkinter shortcuts impossible to enable
Here are some fixes to your code which make it work:
First of all, the key
function should use keysym
member instead of char
of event
:
def key(event): print "pressed", repr(event.keysym)
Then your binding function should use simply the key
function, no need for that lambda. Also you should bind <Control-Key-1>
, not <Control-1>
, (the latter refers to the muse button), so:
for i in range(10): text.bind('<Control-Key-'+str(i)+'>', key)
and you can erase the line:
#text.bind("<Key>", key)
You can also bind the lower case letters like so:
for i in range(ord('a'), ord('z') + 1): text.bind('<Control-Key-'+chr(i)+'>', key)
Hope this helps.