python - Gtk Keybinder 没有响应

标签 python linux gtk

我在 Gtk+3 应用程序中使用 Keybinder,但它没有获得任何组合键。 代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gi
gi.require_version('Keybinder', '3.0')
from gi.repository import Keybinder
from gi.repository import Gtk


def test_func(data):
    print data


if __name__ == '__main__':
    wnd = Gtk.Window()
    wnd.connect('delete-event', Gtk.main_quit)
    wnd.show_all()

    if not Keybinder.bind('<Super>q', test_func, 'Hi there!'):
        print "Keybinder.bind() failed."

    Gtk.main()

我希望当我按下 Windows+q 组合键时程序会执行 test_func,但它什么也没做。 如果有影响的话,我会在 Debian Jessie 上使用 xfce4 运行它。

最佳答案

当您使用基于 GIR 的 Python 绑定(bind)时,我很确定您需要调用

Keybinder.init()

在从 Keybinder 库调用任何其他函数之前手动调用。

(据我所知,静态 python-keybinder Python 绑定(bind)会为您执行此操作,但内省(introspection)绑定(bind)不会。)

关于python - Gtk Keybinder 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19146239/

相关文章:

python - pandas 像磁性一样合并 DataFrame

python - 如何在MSVS2017中安装并运行pytorch(以避免 "module not found"语句上的 "import torch"错误)?

python - pysftp 和 paramiko 在几秒钟后停止上传文件

python - 从 virtualenv 中启动 wsgi 应用程序作为 Linux 系统服务

gtk - 如何制作正确的只读 PyGTK 文本条目?

python - 如何从 python 中的列表中获取第一个值和最后一个值?

php - 用于清除文件的 Web 应用程序

mysql - Ubuntu 18.04 sudo apt-get 更新不起作用

c - 如何在 C 语言的 gtk3 程序中增加按钮或标签的字体大小?

module - 如何创建和加载 GTK 模块?