Trying to create a simple button on kivy, but gave me an error " Only one root object is allowed by .kv"

Viewed 14

This is what i've imported on this app, i'm following a tutorial on YT:

from kivymd.app import MDApp   
from kivy.lang import Builder

the part where i create the button/rectangular button:

KV = """

Screen:

MDRectangleFlatButton:

    text:"Hello Kivy World"
    
    pos_hint: {"center_x": 0.5, "center_y": 0,5 }

            """

The remaining code:

class MainApp(MDApp):
    
    def build(self):
        self.title = "hello kivy"
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Red"
        return Builder.load_string(KV)
        
MainApp().run()

Thanks in advance

1 Answers

This should fix it.

KV = """

<Screen>

    MDRectangleFlatButton:

        text:"Hello Kivy World"
    
        pos_hint: {"center_x": 0.5, "center_y": 0,5 }

            """
Related