标签的颜色没有变化

时间:2018-03-27 20:34:15

标签: python kivy

我正在关注这本书http://shop.oreilly.com/product/0636920032595.do,我似乎无法改变标签的颜色。

这是代码:

from kivy.lang import Builder
from kivy.app import App

root_widget = Builder.load_string('''
<WeatherApp>:
    BoxLayout:

        Label:
            text: 'hey !'
            color: 1, 1, 1, 1
        Label:
            text: 'mark !'
            color: 1, 1, 1, 1
        Label:
            text: 'what is up ?'
            color: 1, 1, 1, 1

''')

class WeatherApp(App):
    pass

if __name__ == '__main__':
    WeatherApp().run()

关于我做错了什么的任何建议?

1 个答案:

答案 0 :(得分:0)

问题不在于Label没有设置颜色,文本的默认颜色是白色,因此无需更改颜色。

问题是你没有加载设计,当你使用时:你只是声明一个小部件,你没有使用它,另外一个App不是一个小部件所以你不应该在设计中声明它。 / p>

下面我展示了更正后的例子:

from kivy.lang import Builder
from kivy.app import App

root_widget = Builder.load_string('''
BoxLayout:
    Label:
        text: 'hey !'
        color: 1, 1, 1, 1
    Label:
        text: 'mark !'
        color: 1, 0, 1, 1
    Label:
        text: 'what is up ?'
''')

class WeatherApp(App):
    def build(self):
        return root_widget

if __name__ == '__main__':
    WeatherApp().run()
相关问题