from kivy.app import App
from kivy.graphics import Line, Color # 引入绘图线条,颜色
from kivy.uix.widget import Widget # 引入控件
from kivy.lang import Builder
from kivy.utils import get_color_from_hex Builder.load_string("""
#:import C kivy.utils.get_color_from_hex
<DrawCanvasWidget>:
canvas.before:
# 最下面纸的颜色
Color:
rgba:[1,1,1,1]
# 形状
Rectangle:
# 位置
pos:self.pos
# 大小
size:self.size
Button:
background_color:C('#FF0000')
text:'1' """) # 布局类
class DrawCanvasWidget(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
# 1.设置默认颜色,在画布中加入颜色 16进制写法 # 画笔的颜色
new_color = get_color_from_hex('#FF0000')
self.canvas.add(Color(*new_color))
# 1.设置默认颜色,在画布中加入颜色 十进制写法传入0到1的浮点数
# self.canvas.add(Color(rgb=[0,0,0])) self.line_width = 1 # 线宽 # 触摸显示轨迹
def on_touch_down(self, touch):
if Widget.on_touch_down(self,touch):
return with self.canvas: touch.ud['current_line'] = Line(points=(touch.x,touch.y),width=self.line_width) # 连线
def on_touch_move(self, touch):
if 'current_line' in touch.ud:
touch.ud['current_line'].points += (touch.x,touch.y) # 应用类
class PaintApp(App):
def build(self):
self.draw_canvas_widget = DrawCanvasWidget()
return self.draw_canvas_widget if __name__ == '__main__': PaintApp().run()

最新文章

  1. NV显卡Ubuntu14.04更新软件导致登录死循环,不过可以进入tty模式
  2. IL初步了解
  3. js控制只能输入数字和控制小数的位数
  4. vuejs
  5. CAS实现单点登入(sso)经典教程
  6. INTERPRETER(解释器)
  7. html meta标签属性用法集合
  8. linux下自动同步internet时间
  9. PyCharm:2017.3版即将新增科学计算模式,预览版现在可以下载使用
  10. 浅谈前后端分离与实践 之 nodejs 中间层服务(二)
  11. 【HDU 2669】Romantic
  12. mysql容灾备份脚本
  13. python3 实例方法、类方法和静态方法
  14. spring security 学习一
  15. Luogu P3177 [HAOI2015]树上染色
  16. vue2.0 之计算属性和数据监听
  17. Catfish CMS漏洞集合
  18. mysql学习之路_乱码问题
  19. 函数和常用模块【day06】:logging模块(八)
  20. [转]http status 汇总

热门文章

  1. Java日期时间API系列42-----一种高效的中文日期格式化和解析方法
  2. ldconfig与 /etc/ld.so.conf
  3. [源码解析] 深度学习分布式训练框架 horovod (20) --- Elastic Training Operator
  4. 274 day04_Map,斗地主案例
  5. centos7 未启用swap导致内存使用率过高。
  6. Linux系列(37) - 源码包与RPM包区别(1)
  7. yapi 事件创建、修改等接口事件监听
  8. iOS之内存管理-字节对齐
  9. java eclipse 使用随笔
  10. 简述编写Django应用的基本步骤