Key Bindings 1-5 not working Tkinter
I have no idea why <6>
works, but the key events are officially called <Key-…>
, see the keysyms manual page:
c.bind_all('<Key-5>', transformation)
EDIT Based on Jason Harper's and Mike - SMT's suggestion, I looked at the Tk source code (in generic/tkBind.c
), and it indeed does this:
if ((*field >= '1') && (*field <= '5') && (field[1] == '\0')) { if (eventFlags == 0) { patPtr->eventType = ButtonPress; eventMask = ButtonPressMask; } else if (eventFlags & KEY) { goto getKeysym; } else if (!(eventFlags & BUTTON)) {… } patPtr->detail.button = (*field - '0'); } else { getKeysym: patPtr->detail.keySym = TkStringToKeysym(field);
So <1>
to <5>
are indeed special-cased as pointer device/mouse buttons. Sneaky.