一个例子说明一切
import kivyfrom random import randomfrom kivy.app import Appfrom kivy.uix.widget import Widgetfrom kivy.uix.button import Buttonfrom kivy.graphics import Color, Ellipse, Lineclass Flowers_back(Widget):
def _my_init(self):
self.x_bef = 0.
self.y_bef = 0.
self.big = 30.
self.c = random(), 1, 1
self.is_start = True
def __init__(self):
super(Flowers_back, self).__init__()
self._my_init()
def on_touch_down(self, touch):
self._my_init()
def on_touch_move(self, touch):
print('hello', touch)
color = self.c with self.canvas:
d = self.big if self.is_start:
self.is_start = False
else:
Color(0, 0, 0, 0.2, mode='rgba')
Ellipse(pos=(self.x_bef - d / 2, self.y_bef - d / 2), size=(d+5, d+5))
Ellipse(pos=(self.x_bef - d / 2 + d, self.y_bef - d / 2 + d), size=(d / 2 +5, d / 2 + 5))
Color(*color, mode='hsv')
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
Ellipse(pos=(touch.x - d / 2 + d, touch.y - d / 2 + d), size=(d/2, d/2))
if self.big <= 80:
self.big += 2.
self.x_bef = touch.x
self.y_bef = touch.yclass TestApp(App):
def build(self):
parent = Widget()
self.painter = Flowers_back()
clearbtn = Button(text='Clear')
clearbtn.bind(on_release=self.clear_canvas)
parent.add_widget(self.painter)
parent.add_widget(clearbtn)
return parent def clear_canvas(self, obj):
self.painter.canvas.clear()if __name__ == '__main__':
TestApp().run()
查看更多关于kivy 的on_touch_move和on_touch_down的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did126880