如何让程序在后台监听键盘事件?

2024-09-26 17:48:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个程序,当我按下自己的快捷键(ctrl+q)时,它将执行多个键盘操作。当程序处于后台时,如何使程序侦听绑定

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_,但是当程序在后台/最小化时,我的绑定什么都不做

我需要一个函数来运行,当我在程序之外并点击我的绑定/快捷键时


Tags: test程序eventbinddefroot键盘快捷键
1条回答
网友
1楼 · 发布于 2024-09-26 17:48:17

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只有在有焦点时才会看到事件。这是其设计的基本部分

相关问题 更多 >

    热门问题