Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect ctrl+click on button in pygtk

Tags:

pygtk

gtk

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.

like image 932
Peter Graham Avatar asked Dec 10 '25 13:12

Peter Graham


1 Answers

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!

like image 149
another.anon.coward Avatar answered Dec 12 '25 13:12

another.anon.coward