当鼠标指针在Entry小部件中时,我希望按下键盘上的任何键(不使用循环)来触发Print:Pressure detected! You pressed any key
.要实现这一点,我应该在函数中写些什么?你能给我们展示一个带有演示代码的解决方案吗?
当前在我的代码中,检测到点击Entry小部件,但我不想得到这个.我想按一下键.
import tkinter as tk
def detects_key_press(event):
print("Pressure detected! You pressed any key")
root = tk.Tk()
entry = tk.Entry(root)
entry.bind("<1>", detects_key_press)
entry.pack(fill="x")
root.mainloop()