Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. from random import random
  2. from kivy.app import App
  3. from kivy.core.window import Window
  4. from kivy.uix.widget import Widget
  5. from kivy.uix.button import Button
  6. from kivy.graphics import Color, Line
  7.  
  8. class DrawInput(Widget):
  9. def on_touch_down(self, touch):
  10. color = (random(), 1., 1.)
  11. with self.canvas:
  12. Color(*color, mode='hsv')
  13. touch.ud["line"] = Line(points=(touch.x, touch.y), width=2)
  14.  
  15. def on_touch_move(self, touch):
  16. touch.ud["line"].points += (touch.x, touch.y)
  17.  
  18. def on_touch_up(self, touch):
  19. print("RELEASED!",touch)
  20.  
  21.  
  22. class SimpleKivy4(App):
  23.  
  24. def build(self):
  25. parent = Widget()
  26. self.painter = DrawInput()
  27. clearbtn = Button(text='Clear')
  28. clearbtn.bind(on_release=self.clear_canvas)
  29. parent.add_widget(self.painter)
  30. parent.add_widget(clearbtn)
  31. return parent
  32.  
  33. def clear_canvas(self, obj):
  34. self.painter.canvas.clear()
  35.  
  36. if __name__ == "__main__":
  37. Window.fullscreen = True
  38. SimpleKivy4().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement