Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a key has been released in tkinter

I am using this code to test whether a key has been pressed, but I also need a binding that is called when a key is released. If no such binding exists, I would settle for a bit of code that continuously checks if the key is still being pressed.

w.bind("<Key>",key)
like image 555
Display name Avatar asked Oct 21 '25 14:10

Display name


1 Answers

This will call onkeyrelease when any key is released:

w.bind("<KeyRelease>", onkeyrelease)

To react to a particular key's release, you would use

w.bind("<KeyRelease-key>", onkeyrelease_of_key)

where key should be replaced by the name of the key.

like image 153
unutbu Avatar answered Oct 23 '25 05:10

unutbu



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!