jeanc
jeanc

Reputation: 4833

Click event on any part of the window with pygtk.Window

I am using pygtk with glade to make a simple program which (by now) consists on:

GUI: A grid 4x4, each one showing an name. Under the grid goes a text Entry. The program runs in fullscreen.

BEHAVIOR: Each name will be "selectable" for 10secs in an infinite loop. "selectable" means that wherever the user makes a click the name which 10secs time is running is selected and put on the TextEntry.

I already made the GUI, but don't know how to handle it for detecting the click anywhere on the screen. Any help?

Upvotes: 2

Views: 3211

Answers (1)

jcollado
jcollado

Reputation: 40374

To detect a click anywhere on the screen you can connect a callback for the button-press-event. Note that this is a gdk event and you must add this event to the mask with the add_events method.

The following small program should be useful:

import gtk

def callback(window, event):
    assert event.type == gtk.gdk.BUTTON_PRESS
    print 'Clicked at x={0}, y={0}'.format(event.x, event.y)

window = gtk.Window()
window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
window.connect('button-press-event', callback)
window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()

gtk.main()

Upvotes: 2

Related Questions