Chubak Chubak - 4 months ago 16
Python Question

Initiating multiple widgets in Kivy

Imagine this as the main.py:

class Widget1(Button)
pass

class Widget2(ButtonBehavior, Image)
pass


And inside the .kv file:

<Widget1>:
Button:

<Widget2>:
Image:


How do I initialize both widget1 and widget2 inside the main file? Creating separate Apps doesn't work.

Answer

Try like this

class Widget1(Button)
    pass

class Widget2(ButtonBehavior, Image)
    pass

class MyMain(Widget):
    pass

class MyApp(App):
    def build(self):
        return MyMain()

MyApp().run()

and in your kivy

<MyMain>:
    <Widget1>:
        Button:

    <Widget2>:
        Image: