如何使用Python中的Tkinter检查当前是否按下了键? [英] How can you check if a key is currently pressed using Tkinter in Python?
问题描述
是否有任何方法可以检测到当前使用Tkinter按下了哪些键?如果可能的话,我不想使用额外的库.我已经可以检测到何时按下了键,但是我希望能够随时检查当前按下了哪些键.
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.
推荐答案
我认为您需要跟踪有关按键和释放键的事件(保持自己的当前按下"键集) )–我相信Tk不会为您跟踪(Tkinter确实在Tk的基础上添加了很少的东西,主要是它的直接接口).
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).
这篇关于如何使用Python中的Tkinter检查当前是否按下了键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!