簡體   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