【问题标题】:KIVY: Changing line colour in Paint AppKIVY:在 Paint App 中更改线条颜色
【发布时间】:2017-04-19 16:35:52
【问题描述】:

如何在我制作的 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()

【问题讨论】:

    标签: python python-2.7 kivy kivy-language


    【解决方案1】:

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

    from kivy.graphics import Line, Color
    

    然后在您的 Painter 类中将颜色添加到画布。在此示例中,我尝试使用红色。
    它的 rgba 值。

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

    【讨论】:

    • 非常感谢!!我错过了导入颜色。这让生活变得悲惨。
    • @thechargedneutron 你很高兴 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 2018-12-30
    相关资源
    最近更新 更多