我正在制作一个程序,当我按下自己的快捷键(ctrl+q)时,该程序将执行多个键盘操作。当程序在后台运行时,如何让我的程序监听绑定(bind)?
def pasteFun(event):
messagebox.showinfo("hey")
root.bind("<Control-q>", pasteFun)
当我在程序中时,这工作得很好,但是当我最小化它时,ctrl+q 不执行任何操作。
def test(event):
messagebox.showinfo("hey","hey")
root.bind_all("<Control-q>",test)
我尝试过 root.bind、frame.bind 和 root.bind_all,但当程序处于后台/最小化时,我的绑定(bind)什么也不做。
当我在程序之外并点击我的绑定(bind)/快捷方式时,我需要一个函数来运行。
最佳答案
I'm making a program that will do multiple keyboard actions when I press my own shortcut (ctrl+q). How do I make my program listen to the binds when the program is in the background?
使用 tkinter 无法做到这一点。 Tkinter 仅在获得焦点时才会看到事件。这是其设计的基本部分。
关于python - 如何让程序在后台监听键盘事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58758115/