[Python] line 987, in add_widget raise ScreenManagerException(...

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    I keep getting this error: line 987, in add_widget raise ScreenManagerException( kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.

    I've tried everything. Posted all my code to Grok and that found no issues. I've cleared cache, uninstalled and reinstalled kivy and dependencies, watched videos on youtube and copied code exactly and I keep getting the error.

    Does anyone have any ideas??!?!?!?!

    heres my main.py:


    from kivy.app import App
    from kivy.lang import Builder
    from kivy.uix.screenmanager import Screen, ScreenManager
    from kivy.logger import Logger


    class WindowManager(ScreenManager):
    pass
    class HomeScreen(Screen):
    pass
    class Settings(Screen):
    pass
    class QueryPage(Screen):
    pass


    try:
    GUI = Builder.load_file('main.kv')
    except Exception as e:
    Logger.error(f"Failed to load main.kv: {e}")

    raise
    #
    # GUI = Builder.load_file("main.kv")
    class SQLTutor(App):
    def build(self):
    return GUI

    def change_screen(self, screen_name):
    # Change the screen by setting the current screen's name
    self.root.current = screen_name


    # def change_screen(self, screen_name):
    # print(self.root.ids)
    # # screen_manager = self.root.ids


    if __name__ == "__main__":
    SQLTutor().run()

    and also my main.kv:


    #:kivy 2.3.1

    WindowManager:
    HomeScreen:
    name: 'home_screen'
    id: home_screen
    Settings:
    name: 'settings'
    id: settings
    QueryPage:
    name: 'query_page'
    id: query_page

    <HomeScreen>:
    BoxLayout:
    orientation: 'vertical'
    size: root.width, root.height
    Button:
    text: 'You are on the Home Screen'
    on_release: app.change_screen('settings')

    <Settings>:
    BoxLayout:
    orientation: 'vertical'
    size: root.width, root.height
    Button:
    text: 'You are on the Settings Screen'
    on_release: app.change_screen('query_page')

    <QueryPage>:
    BoxLayout:
    orientation: 'vertical'
    size: root.width, root.height
    Button:
    text: 'You are on the Query Page'
    on_release: app.change_screen('home_screen')


    I've been working for 4 hrs trying to figure it out and I keep getting the same error.

    Continue reading...

Compartilhe esta Página