我找到了一段代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
class Test(BoxLayout):
def __init__(self, **kwargs):
super(Test, self).__init__(**kwargs)
Window.bind(on_touch_down=self.window_on_touch_down)
def window_on_touch_down(self, *args):
print(args)
# scrolling the wheel down will give <MouseMotionEvent button="scrollup"
if '<MouseMotionEvent button="scrollup"' in args:
print('hello')
class TestApp(App):
def build(self):
return Test()
if __name__ == '__main__':
TestApp().run()当它打印滚动运动时,我不能用它.args里面有字符串,但是if不起作用,"hello“也没有打印出来.有人知道为什么吗?
发布于 2020-05-28 19:36:14
您在打印中看到的是python对象,而不是字符串。
所以你不能只检查一根绳子。
获取所需内容的更好方法是检查哪个按钮生成MouseMotionEvent
def window_on_touch_down(self, window, mouse_event):
# scrolling the wheel down will give <MouseMotionEvent button="scrollup"
if mouse_event.button == "scrollup":
print('hello')https://stackoverflow.com/questions/62071786
复制相似问题