Unable to add new screen via screen manager in kivy application

60 Views Asked by At

I am trying to add the new connect screen. I am using screen manager. I also updated the kv file. I was able to run the app with one screen, when I added new screen, I am getting the below error :

raise FactoryException('Unknown class <%s>' % name)
 kivy.factory.FactoryException: Unknown class <ConnectScreen>

Now My firstapp.kv is as below :

...
#:import AboutScreen screens
#:import ContactScreen  screens

NavigationLayout:
    id: nav_layout
    MDNavigationDrawer:
        id: nav_drawer
        NavigationDrawerToolbar:
            title: 'Menu'
        NavigationDrawerIconButton:
            icon: 'arrow-right-drop-circle'
            text: 'About Us'
            on_release: app.root.ids.scr_mngr.current = 'about'
        NavigationDrawerIconButton:
            icon: 'arrow-right-drop-circle'
            text: 'Connect Us'
            on_release: app.root.ids.scr_mngr.current = 'connect'

    BoxLayout:
        orientation: 'vertical'
        Toolbar:
            id: toolbar
            title: 'Main Dashboard'
            md_bg_color: app.theme_cls.primary_color
            background_palette: 'Primary'
            background_hue: '500'
            left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]]
        ScreenManager:
            id: scr_mngr
            AboutScreen:
            ConnectScreen:

Now I have also updated the Builder.load.string my connect.py is as below :

#!/usr/bin/env python
# -*- coding: utf-8 -*-


from kivy.lang import Builder
from kivy.uix.screenmanager import Screen

Builder.load.string("""
<AboutScreen>
    name: 'connect'
    ScrollView:
        id: scroll
        do_scroll_x: False
        BoxLayout:
            orientation: 'vertical'
            size_hint_y: None
            height: dp(800)
            padding: dp(15)
            spacing: dp(15)
            Image:
                source: './img/connect.jpeg'
                allow_stretch: True
""")


class ConnectScreen(Screen):
    pass

How can I solve this?

1

There are 1 best solutions below

1
On BEST ANSWER

Found the issue.

My __init__.py ( in screens folder) was not updated.

After I updated my __init__.py, it worked.

from .contact import ContactScreen