当前位置:   article > 正文

kivy 画图实例_kivy实例

kivy实例
  1. from kivy.app import App
  2. from kivy.graphics import Line, Color
  3. from kivy.uix.widget import Widget
  4. from kivy.core.text import LabelBase
  5. from kivy.utils import get_color_from_hex
  6. get_color_from_hex("#19cadd")
  7. LabelBase.register("Roboto", "HelloKitty.TTF")
  8. class DrawCanvasWidget(Widget):
  9. def __init__(self,**kwargs):
  10. super(DrawCanvasWidget, self).__init__(**kwargs)
  11. # 设置默认值
  12. self.change_color(get_color_from_hex("#19caad"))
  13. self.canvas.add(Color(rgb=[0, 0, 0]))
  14. self.line_width = 2
  15. def on_touch_down(self, touch):
  16. """触摸显示轨迹"""
  17. if Widget.on_touch_down(self, touch):
  18. return
  19. with self.canvas:
  20. touch.ud["current_line"] = Line(points=(touch.x, touch.y), width=self.line_width)
  21. def on_touch_move(self, touch):
  22. """连线"""
  23. if "current_line" in touch.ud:
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号