How can you check if a key is currently pressed using Tkinter in Python?
-
19-09-2019 - |
Question
Is there any way to detect which keys are currently pressed using Tkinter? I don't want to have to use extra libraries if possible. I can already detect when keys are pressed, but I want to be able to check at any time what keys are pressed down at the moment.
Solution
I think you need to keep track of events about keys getting pressed and released (maintaining your own set of "currently pressed" keys) -- I believe Tk doesn't keep track of that for you (and Tkinter really adds little on top of Tk, it's mostly a direct interface to it).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow