不知道为什么在释放按钮时会触发 on_touch_up。其他两个事件 on_touch_down 和 on_touch_move 不会被触发。
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
print "on_touch_down"
def on_touch_move(self, touch):
print "on_touch_move"
def on_touch_up(self, touch):
print "on_touch_up"
class MyPaintApp(App):
def build(self):
parent = Widget()
painter = MyPaintWidget()
btn = Button(text='Click Me')
parent.add_widget(painter)
parent.add_widget(btn)
return parent
if __name__ == '__main__':
MyPaintApp().run()