我在网上使用以下代码:
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Line
class DrawInput(Widget):
def on_touch_down(self, touch):
print(touch)
with self.canvas:
touch.ud["line"] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
print(touch)
touch.ud["line"].points += (touch.x, touch.y)
def on_touch_up(self, touch):
print("RELEASED!", touch)
class SimpleKivy4(App):
def build(self):
return DrawInput()
if __name__ == "__main__":
SimpleKivy4().run()
为什么方法on_touch_down(self, touch)
即使没有在任何地方显式调用也能实现?
编辑:如果widget
根据触摸发生的时间触发。那么DrawInput()
函数on_touch_down
如何被触发。原因课程Widget
并不了解DrawInpout()
课程或其任何方法。
答案 0 :(得分:0)
它们被调用,因为它们是您覆盖的Widget类方法。 它们是在Widget上点击/触摸的事件。
来自Widget文档
活动:
on_touch_down:
新触摸事件发生时触发on_touch_move:
在现有触摸移动时触发on_touch_up:
当现有触摸消失时触发