检测Ctrl +单击pygtk中的按钮 [英] Detect ctrl+click on button in pygtk

查看:48
本文介绍了检测Ctrl +单击pygtk中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测用户单击按钮时是否按住ctrl. 点击"信号似乎没有将足够的信息传递给回调以解决此问题.

I want to detect if ctrl is held down when the user clicks a button. The 'clicked' signal doesn't seem to pass enough information to the callback to work this out.

推荐答案

如果您可以连接到 button-release-event 而不是clicked,传递给回调的event可用于获取修改器状态(使用

If you can connect to either button-press-event or button-release-event instead of clicked, the event passed to the callback can be used to get the modifier state (using get_state) and check if control key is pressed. For ex.

def button_release_callback(widget, event, data=None):
    if event.get_state() &  gtk.gdk.CONTROL_MASK:
        print "Ctrl held"
    else:
        print "Ctrl not held"
...
button.connect("button-release-event", button_release_callback)

希望这会有所帮助!

这篇关于检测Ctrl +单击pygtk中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆