3

i have a (large) python tkinter canvas. Navigation with arrow keys and (shift-)mousewheel is straight forward. But I would like to do it aswell via two fingers on the tochpad of a laptop.

Today I found this to recognize horizontal scrolling (Ubuntu 16.04 LTS, Python 2.x):

from Tkinter import *

class MyAnything():
    def __init__(self):
        self.root = Tk()
        self.root.bind('<Button>', self.on_pressed_button)
        self.root.mainloop()

    def on_pressed_button(self, event):
        print(event.num)

if __name__ == '__main__':
    myanything = MyAnything()

Using mouse and touchpad I get 1 - 5 anyways, but also 6 and 7 (touchpad).

But this generates an error: "_tkinter.TclError: specified keysym "6" for non-key event".

self.root.bind('<Button-6>', self.on_pressed_button)

I find this very wierd. It works but doesn't feel right.

On the other hand, it would be nice if somebody can tell a solution for Windows. Until now i only know <MouseWheel>. Do I need to give more info? Thanks in advance.

wilbot
  • 31
  • 2
  • Here's a related question I asked and answered (which may or may not provide insights for you): https://stackoverflow.com/questions/46194948/what-are-the-tkinter-events-for-horizontal-edge-scrolling-in-linux/46194949#46194949 If you can get `event.num` you should be able to do horizontal mouse scrolling without interfering with other buttons without binding any event name other than `" – Brōtsyorfuzthrāx Sep 13 '17 at 11:35

0 Answers0