ZIP用python+kivy实现简易的电子白板功能 1.57KB

sunch007需要积分:5(1积分=1元)

资源文件列表:

paint.zip 大约有2个文件
  1. main_paint.py 1.7KB
  2. paint.kv 1.69KB

资源介绍:

用python+kivy实现简易的白板功能:具有以下功能: 1.显示画笔轨迹 2.设置画笔的颜色,可选择10种颜色,可修改代码添加 3.设置线条的粗细,也叫线宽(提供三个选择:细、正常、粗) 4.清屏
from kivy.uix.behaviors import ToggleButtonBehavior from kivy.uix.togglebutton import ToggleButton from kivy.app import App from kivy.graphics import Line, Color from kivy.uix.widget import Widget class FrameToggleButton(ToggleButton): # 当前按钮添加边框 def do_press(self): # 点击改变状态 if self.state == 'normal': ToggleButtonBehavior.do_press(self) class DrawCanvasWidget(Widget): def __init__(self, **kwargs): super().__init__(**kwargs) # set default color self.canvas.add(Color(rgb=[0,0,0])) self.line_width = 2 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) def change_color(self, new_color): # 调色 self.last_color = new_color self.canvas.add(Color(*new_color)) def change_line_width(self, line_width='Normal'): # 线宽 self.line_width = {'Thin': 1, 'Normal': 2, 'Thick': 4}[line_width] def clear_canvas(self): # 清屏 saved = self.children[:] self.clear_widgets() self.canvas.clear() for widget in saved: self.add_widget(widget) self.change_color(self.last_color) class PaintApp(App): def build(self): self.draw_canvas_widget = DrawCanvasWidget() return self.draw_canvas_widget if __name__ == '__main__': pa = PaintApp() pa.run()
100+评论
captcha
    类型标题大小时间
    ZIP超星学习通学习专用浏览器92.63MB7月前
    ZIPDjango相关知识点笔记代码等51.21MB7月前
    ZIP23级虚拟现实技术一班 2024-2025学年贫困认定.zip31.55KB7月前
    ZIP基于CH32的全屋灯光智能控制系统源代码(项目分享-小白练手项目)2.1MB7月前
    ZIPstm32f4+ads1278.zip5.23MB7月前
    ZIP基于springcloud的脚手架(smart-cloud)示例.zip571.76KB7月前
    ZIP全民帮帮是一款通用性的互相帮助、跑腿、中介、同城等综合性业务的APP开源软件,具有一定通用性、普惠性,互助性,全民性.zip6.17MB7月前
    ZIPgo-micro2.x微服务,etcd作为服务注册发现中间件.zip338.01KB7月前