用kivy语言设置实例的颜色

时间:2015-06-20 16:14:39

标签: python python-2.7 kivy

我想知道是否有办法在.kv文件中设置圆圈实例的颜色?

我的.kv文件:

<Circle>:
    canvas:
        Ellipse:
            pos: self.pos
            size: self.size
<MyClass>:
    circle1: _circle1
    circle2: _circle2

    Circle:
        id: _circle1
        size: 250,250
        center_x: self.parent.width / 4
        center_y: self.parent.height / 2

    Circle:
        id: _circle2
        size: 250,250
        center_x: self.parent.width * 3/4
        center_y: self.parent.height / 2

1 个答案:

答案 0 :(得分:1)

您可以使用颜色执行此操作。 Go here在画布上阅读更多内容。

您可以根据需要使用canvas.before,canvas.after,self.canvas和其他一些方法。

请注意,它需要0-1而不是0-255的值。 因此,如果您的值在0-255之间,则将其除以255并使用它。

   <Circle>: 
        canvas.before:
            Color:
                rgba: .2,.5,.5,1
            Ellipse::   
                pos: self.pos
                size: self.size

这是github上的colorpicker.py颜色选择。