【问题标题】:Set the color of an instance in kivy language用kivy语言设置实例的颜色
【发布时间】:2015-06-21 01:02:21
【问题描述】:

我想知道是否有任何方法可以在 .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

【问题讨论】:

    标签: python python-2.7 kivy


    【解决方案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 用于颜色选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多