Detect ctrl+click on button in pygtk

眉间皱痕 提交于 2019-12-22 18:29:28

问题


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.


回答1:


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)

Hope this helps!



来源:https://stackoverflow.com/questions/13371968/detect-ctrlclick-on-button-in-pygtk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!