Home > database >  how to detect a key press when a mouse click happened in tkinter canvas
how to detect a key press when a mouse click happened in tkinter canvas

Time:07-15

I have a canvas with a rectangle and I want to detect if someone pressed the rectangle together with a key (ie "shift"). screenshot of window with red and green canvas items

If you want to handle multiple combinations of modifier keys (alt, shift, control, meta, etc) you can bind to <1> and examine the state attribute of the event object. However, there are platform dependencies that make that problematic. I personally find making individual bindings easier and more straight-forward.

For more on how to use the event.state attribute, see check if modifier key is pressed in tkinter

  • Related