Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
I逗
Python Kivy
提交
2f298130
P
Python Kivy
项目概览
I逗
/
Python Kivy
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Python Kivy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2f298130
编写于
9月 11, 2021
作者:
I逗
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
更新drawmain.py, paint.kv
上级
a324b4e3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
176 addition
and
0 deletion
+176
-0
drawmain.py
drawmain.py
+78
-0
paint.kv
paint.kv
+98
-0
未找到文件。
drawmain.py
0 → 100644
浏览文件 @
2f298130
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 10 13:58:05 2021
@author: flameabc
@dec: draw
简易画板,熟悉.kv文件,布局,按钮分布。。。
"""
from
kivy.app
import
App
from
kivy.graphics
import
Line
,
Color
from
kivy.uix.widget
import
Widget
from
kivy.utils
import
get_color_from_hex
from
kivy.uix.behaviors
import
ToggleButtonBehavior
from
kivy.uix.togglebutton
import
ToggleButton
class
DrawCanvasWidget
(
Widget
):
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
""" 设置默认颜色 """
self
.
change_color
(
get_color_from_hex
(
'#19caad'
))
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
FrameToggleButton
(
ToggleButton
):
""" 当前按钮添加边框 """
def
do_press
(
self
):
""" 点击改变状态 """
if
self
.
state
==
'Normal'
:
ToggleButtonBehavior
.
do_press
(
self
)
class
PaintApp
(
App
):
def
build
(
self
):
self
.
draw_canvas_widget
=
DrawCanvasWidget
()
return
self
.
draw_canvas_widget
if
__name__
==
'__main__'
:
PaintApp
().
run
()
paint.kv
0 → 100644
浏览文件 @
2f298130
#:import C kivy.utils.get_color_from_hex
<BottomColorButton@ToggleButton>:
group: 'color'
background_normal: 'radio_background_normal.png'
background_down: 'radio_background_down.png'
border: (3, 3, 3, 3)
on_release: app.draw_canvas_widget.change_color(self.background_color)
<LineWidgetButton@ToggleButton>:
group: 'line_width'
color: C('#2c3e50')
background_color: C('#ecf0f1')
background_normal: 'radio_background_normal.png'
background_down: 'radio_background_down.png'
border: (3, 3, 3, 3)
on_release: app.draw_canvas_widget.change_line_width(self.text)
<DrawCanvasWidget>:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
BoxLayout:
orientation: 'horizontal'
padding: 2
spacing: 2
x: 0
top: root.top
size_hint: None, None
size: 280, 40
LineWidgetButton:
text: 'Thin'
LineWidgetButton:
text: 'Normal'
state: 'down'
LineWidgetButton:
text: 'Thick'
Button:
text: 'Clear'
on_release: root.clear_canvas()
BoxLayout:
id: botton_box
orientation: 'horizontal'
padding: 2
spacing: 2
size: root.width, 40
BottomColorButton:
background_color: C('#19caad')
state: 'down'
BottomColorButton:
background_color: C('#8cc7b5')
BottomColorButton:
background_color: C('#a0eee1')
BottomColorButton:
background_color: C('#bee7e9')
BottomColorButton:
background_color: C('#beedc7')
BottomColorButton:
background_color: C('#d6d5b7')
BottomColorButton:
background_color: C('#d1ba74')
BottomColorButton:
background_color: C('#e6ceac')
BottomColorButton:
background_color: C('#ecad9e')
BottomColorButton:
background_color: C('#f4606c')
BottomColorButton:
background_color: C('#3498db')
BottomColorButton:
background_color: C('#1abc9c')
BottomColorButton:
background_color: C('#2ecc71')
BottomColorButton:
background_color: C('#f1c40f')
BottomColorButton:
background_color: C('#e67e22')
BottomColorButton:
background_color: C('#e74c3c')
BottomColorButton:
background_color: C('#9b59b6')
BottomColorButton:
background_color: C('#ecf0f1')
BottomColorButton:
background_color: C('#95a5a6')
BottomColorButton:
background_color: C('#000000')
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录