Shree Singhi
Shree Singhi

Reputation: 832

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?

Upvotes: 0

Views: 1134

Answers (1)

inclement
inclement

Reputation: 29488

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

Upvotes: 2

Related Questions