python - KIVY:在 Paint App 中更改线条颜色

标签 python python-2.7 kivy kivy-language

如何更改我制作的 kivy Paint 应用程序中的线条颜色。我可以更改线条宽度,但找不到任何可以更改线条颜色的内容。

我的代码:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Line
class DrawRandom(Widget):
    def on_touch_down(self, touch):
        with self.canvas:
            touch.ud["line"]=Line(points=(touch.x,touch.y),width=5)
    def on_touch_move(self, touch):
        touch.ud["line"].points += (touch.x, touch.y)

class PaintApp(App):
    def build(self):
        return DrawRandom()


if __name__ == "__main__":
    PaintApp().run()

最佳答案

您只需将颜色添加到 Canvas 即可。
在您的导入中也导入颜色。

from kivy.graphics import Line, Color

并在您的 Painter 类中将颜色添加到 Canvas 。在这个例子中我尝试红色。
它的 rgba 值。

def on_touch_down(self, touch):
    with self.canvas:
        Color(1,0,0,1)
        touch.ud["line"] = Line( points = (touch.x, touch.y))

关于python - KIVY:在 Paint App 中更改线条颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43501386/

相关文章:

python - 类变量的 Getter 或 Property 函数

python - 重构处理 "overrides of default parameters"的小代码

Python 类型错误 : expected string or buffer

python-3.x - 切换音乐开/关 Kivy

opencv - 属性错误 : module 'cv2' has no attribute 'face' despite using "opencv_extras" recipe

python - python中如何将一个字符串复制到另一个字符串

python - 替换 Numpy 数组列表中的值

python - 从 VS Code 集成终端运行 Python 时,matplotlib 图不会显示

python - 写入 xlsx 在一个单元格中创建重复行

python - 如何在 python 中引用 Kivy Canvas