Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tkinter check if Shift is down when Button is pressed

I have a tk.Button(..., command=_on_button_click).
Once it is clicked, I want to know whether the Shift key is currently held down.

But the _on_button_click is called without any event object or similar for me to check it

like image 695
user972014 Avatar asked Aug 01 '26 17:08

user972014


1 Answers

Assuming a button named button and a handler named shift_click, you can use the bind method:

button.bind("<Shift-Button-1>", shift_click)

Of course, you will probably also want one without shift click:

button.bind("<Button-1>", not_shift_click)

like image 101
AlgoRythm Avatar answered Aug 03 '26 08:08

AlgoRythm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!