繁体   English   中英

更改标签颜色

[英]Change Label Color

请帮助我正在尝试使用 objectproperty 来更改标签的颜色。 该函数有效,因为它在控制台中打印出来。 标签颜色或文字不会改变,但我不确定我做错了什么。

<Box3@BoxLayout>:
    GridLayout:

        indicator: my_indicator
        cols: 1
        size: root.width/3, root.height/2

        Label:
            id: my_indicator
            pos: self.pos
            text: 'test'
            canvas.before:
                Color:
                    rgba: (1.0, 0.0, 0.0, 1.0)
                Rectangle:
                    pos: self.pos
                    size: self.size
class main_kv(GridLayout):

    indicator = ObjectProperty(Widget)
    activate = ObjectProperty(None)

    def changeColour(self):

        self.indicator.color = 1,0,1,1
        self.indicator.text = 'changed'
        print('button clicked')

    pass

        Button:
            id: activate
            text: 'Arm'
            on_press: app.root.changeColour()
            background_color: (0.4, 0.7, 0.8, 1.0)
            pos: self.parent.center
            font_size: 40
            opacity: 0.8

尝试使用 init 函数创建指标并激活对象:

class main_kv(GridLayout):

    def __init__(self):
        self.indicator = ObjectProperty(Widget)
        self.activate = ObjectProperty(None)

    def changeColour(self):

        self.indicator.color = 1,0,1,1
        self.indicator.text = 'changed'
        print('button clicked')

    pass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM