问题
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