python tkinter: detecting horizontal scrolling on touchpad

喜欢而已 提交于 2019-12-02 02:04:21

问题


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.

来源:https://stackoverflow.com/questions/44331424/python-tkinter-detecting-horizontal-scrolling-on-touchpad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!