0

My code was pretty simple but it ended up running and closing with the message : "kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget." at the bottom, any ideas on what this might mean?

Code1 Code2

1 Answers1

0

I will suggest you following project structure:

main.py  - Python main program
crying.kv - screens definition KV file (filename same as app class name, lowercase)
main.kv - main screen KV file
login.kv - login screen KV file
signup.kv - signup screen KV file

main.py

from kivymd.app import MDApp
from kivy.core.window import Window
from kivymd.uix.screenmanager import MDScreenManager
from kivymd.uix.screen import MDScreen

class MyAppScreens(MDScreenManager):
    pass

class MainScreen(MDScreen):
    pass

class LoginScreen(MDScreen):
    pass

class SignupScreen(MDScreen):
    pass

class Crying(MDApp):
    pass

if __name__ == '__main__':
    Window.size = (310, 580)
    Crying().run()

crying.kv

#:include main.kv
#:include login.kv
#:include signup.kv

MyAppScreens:
    MainScreen:
    LoginScreen:
    SignupScreen:

main.kv

<MainScreen>:
    name: 'main'

    MDBoxLayout:
        orientation: 'vertical'
        adaptive_size: True
        pos_hint: {"center_x": .5, "center_y": .5}
        spacing: 20

        MDRaisedButton:
            text: 'Login'
            pos_hint: {"center_x": .5, "center_y": .5}
            on_release: root.manager.current = 'login'

        MDRaisedButton:
            text: 'Signup'
            pos_hint: {"center_x": .5, "center_y": .5}
            on_release: root.manager.current = 'signup'

login.kv

<LoginScreen>:
    name: 'login'

    MDBoxLayout:
        orientation: 'vertical'
        adaptive_size: True
        pos_hint: {"center_x": .5, "center_y": .5}
        spacing: 20

        MDLabel:
            text: 'Login Screen'
            halign: "center"

        MDRaisedButton:
            text: 'Back tp main'
            pos_hint: {"center_x": .5, "center_y": .5}
            on_release: root.manager.current = 'main'

signup.kv

<SignupScreen>:
    name: 'signup'

    MDBoxLayout:
        orientation: 'vertical'
        adaptive_size: True
        pos_hint: {"center_x": .5, "center_y": .5}
        spacing: 20

        MDLabel:
            text: 'Signup Screen'
            halign: "center"

        MDRaisedButton:
            text: 'Back to main'
            pos_hint: {"center_x": .5, "center_y": .5}
            on_release: root.manager.current = 'main'
MST
  • 651
  • 1
  • 4
  • 6