FAQ Index - Search - Recent Changes - Everything - Add entry

<< Previous Entry | FAQ Entry 5.19 | Next Entry >>

5.19. How can I listen to events from the scroll wheel on my mouse?

To listen for events that your scroll wheel sends you need to connect to the signal 'scroll-event'. The event structure has a direction attribute which will be one of:

  gtk.gdk.SCROLL_UP, 
  gtk.gdk.SCROLL_DOWN, 
  gtk.gdk.SCROLL_LEFT, 
  gtk.gdk.SCROLL_RIGHT
Example:

  def on_button_scroll_event(button, event):
    if event.direction == gtk.gdk.SCROLL_UP:
       print "You scrolled up"

  b = gtk.Button()
  b.connect('scroll-event', on_button_scroll_event)

PyGTK FAQ Wizard | PyGTK Homepage | Feedback to faq at pygtk.org