Open Technical Blog
Monday, 3 November 2014
Mouse Scroll Event Handler
The script shows the way to capture the mouse scroll event by a GTK3 window.
Define a scroll-event handler in a window.
Both scroll up and scroll down can be detected.
Source Code
#!/usr/bin/python from gi.repository import Gtk, Gdk class MyWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Mouse Scroll") self.connect("delete-event", Gtk.main_quit) self.set_default_geometry(width=300, height=200) self.label = Gtk.Label("Sroll mouse wheel") self.add_events(Gdk.EventMask.SCROLL_MASK) self.connect('scroll-event',self.onScroll) self.count = 0 self.add(self.label) def onScroll(self, button, event): mStr = "" if event.direction == Gdk.ScrollDirection.UP: mStr = "Scroll up" self.count += 1 elif event.direction == Gdk.ScrollDirection.DOWN: mStr = "Scroll down" self.count -= 1 mStr = mStr + " (%d)" % self.count self.label.set_text(mStr) win = MyWindow() win.show_all() Gtk.main()
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment