I am trying to add a simple label to a screen using Python and Kivy. I know how to do it using the Builder.load_string() method, but I wish to do it using the Kivy library through Python.
When I run the code below I get a blank purple screen, but when I put the label into the Builder.load_string() method it works fine. What am I doing wrong?
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager, Screen
Builder.load_string("""
<HomePage>:
FloatLayout:
canvas.before:
Color:
rgb: .5,0,.75
Rectangle:
size: self.size
""")
class HomePage(Screen):
layout = FloatLayout()
home_title = Label(text="text")
layout.add_widget(home_title)
class LabelApp(App):
def build(self):
sm = ScreenManager()
sm.add_widget(HomePage(name='home'))
retu sm
if __name__ == "__main__":
LabelApp().run()
