'How to get a Background color on a Kivy Label?

I am using Kivy to make an app, and I'm trying to display a label. Here's my main code


from kivy.app import App

from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from kivy.uix.popup import Popup

class storageApp(App):
    def build(self):
        return kvfile

class LoginPage(Screen):
    pass

class WindowManager(ScreenManager):
    pass

kvfile = Builder.load_file('storage.kv')


storageApp().run()

Here's my .kv file

WindowManager:
    current: 'login'
    LoginPage:

<LoginPage>:
    name: 'login'
    FloatLayout:
        Label:
            text: 'Welcome to the secret app!'
            size_hint: 0.5, 0.1
            pos_hint: {'center_x': 0.5, 'top': 0.95}
            background_color: 1, 0, 1, 1

And I get the following output on my screen

screen

The color of the label is still black. However, when Ichange the Label to Button it seems to work.

enter image description here

This seems very odd. Any idea how to fix it?



Solution 1:[1]

The Label doesn't have a background colour property. If you want a background, draw one:

<KvBackgroundRule>:
    canvas.before:
        Color:
            rgba: 1, 0, 0, 1
        Rectangle:
            pos: self.pos
            size: self.size

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 inclement