0

Hi guys i am new to KivyMD and working on my first app. Basically i need to open a new screen on click on the contents in my navigation drawer. For instance i have a New Room button on my nav drawer and i want a new screen to be opened when i click on it.

Okay here's my code

from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from home_page_strings import toolbar


class EMC_WebmaApp(MDApp):
    def build(self):
        screen = Screen()

        # theme settings
        self.theme_cls.primary_palette = 'DeepPurple'
        self.theme_cls.theme_style = 'Dark'
        # end of theme declaration

        # loaded strings
        navigation_bar = Builder.load_string(toolbar)
        # end of loaded strings

        # addition of loaded strings to screen + return screen
        screen.add_widget(navigation_bar)

        return screen
        # end of addition


EMC_WebmaApp().run()

And here's my string

toolbar = '''
Screen:
    NavigationLayout:
        ScreenManager:
            Screen:  
                BoxLayout:
                    orientation: 'vertical'
                    
                    MDToolbar:
                        title: 'EMC_Webma'
                        left_action_items: [['menu', lambda x: navigation.set_state('open')]]
                        right_action_items: [['card-search', lambda x: print('pass')]]
                        elevation: 10
                            
                           
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 1'
                            secondary_text: '[Recent text here]'
                            
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 2'
                            secondary_text: '[Recent text here]'
                            
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 3'
                            secondary_text: '[Recent text here]'
                        
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 4'
                            secondary_text: '[Recent text here]'
                    
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 5'
                            secondary_text: '[Recent text here]'
                            
                    MDList:
                        TwoLineListItem:
                            text: 'Friend 6'
                            secondary_text: '[Recent text here]'

                    Widget:
                    
        MDNavigationDrawer:
            id: navigation
            
            BoxLayout:
                orientation: 'vertical'
                spacing: '8dp'
                padding: '8dp'
                            
                Image:
                    source: 'einstein.jpg'
                    
                MDLabel:
                    text: 'Enwerem Melvin Confidence'
                    font_style: 'Subtitle2'
                    size_hint_y: None
                    height: self.texture_size[1]
                    
                MDLabel:
                    text: 'enweremmelvinconfidence@gmail.com'
                    font_style: 'Caption'
                    size_hint_y: None
                    height: self.texture_size[1]
                                    
                ScrollView:
                    MDList:
                        OneLineIconListItem:
                            text: 'New Room'
                            IconLeftWidget:
                                icon: 'theater'
                                
                        OneLineIconListItem:
                            text: 'Contacts'
                            IconLeftWidget:
                                icon: 'contacts'
                                
                        OneLineIconListItem:
                            text: 'Calls'
                            IconLeftWidget:
                                icon: 'cellphone-android'
                                
                        OneLineIconListItem:
                            text: 'Settings'
                            IconLeftWidget:
                                icon: 'settings'
                                
                        OneLineIconListItem:
                            text: 'FAQ'
                            IconLeftWidget:
                                icon: 'frequently-asked-questions'
                                
                        OneLineIconListItem:
                            text: 'Invite Friends'
                            IconLeftWidget:
                                icon: 'account-plus'
                                
                        OneLineIconListItem:
                            text: 'Toggle Theme'
                            IconLeftWidget:
                                icon: 'theme-light-dark'
'''

Thanks for helping

1 Answers1

1
from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
MDScreen:

    MDNavigationLayout:

        ScreenManager:
            id: manager

            MDScreen:
                name: 'screen 1'

                MDBoxLayout:
                    orientation: 'vertical'
                    
                    MDToolbar:
                        title: 'EMC_Webma'
                        left_action_items: [['menu', lambda x: navigation.set_state('open')]]
                        right_action_items: [['card-search', lambda x: print('pass')]]
                        elevation: 10
                            
                    ScrollView:

                        MDList:
                            TwoLineListItem:
                                text: 'Friend 1'
                                secondary_text: '[Recent text here]'
                                
                            TwoLineListItem:
                                text: 'Friend 2'
                                secondary_text: '[Recent text here]'
                                
                            TwoLineListItem:
                                text: 'Friend 3'
                                secondary_text: '[Recent text here]'
                            
                            TwoLineListItem:
                                text: 'Friend 4'
                                secondary_text: '[Recent text here]'
                        
                            TwoLineListItem:
                                text: 'Friend 5'
                                secondary_text: '[Recent text here]'
                                
                            TwoLineListItem:
                                text: 'Friend 6'
                                secondary_text: '[Recent text here]'

            MDScreen:
                name: 'screen 2'
                
                MDLabel:
                    text: "Screen 2"

        MDNavigationDrawer:
            id: navigation
            
            MDBoxLayout:
                orientation: 'vertical'
                spacing: '8dp'
                padding: '8dp'
                            
                Image:
                    source: 'einstein.jpg'
                    
                MDLabel:
                    text: 'Enwerem Melvin Confidence'
                    font_style: 'Subtitle2'
                    size_hint_y: None
                    height: self.texture_size[1]
                    
                MDLabel:
                    text: 'enweremmelvinconfidence@gmail.com'
                    font_style: 'Caption'
                    size_hint_y: None
                    height: self.texture_size[1]
                                    
                ScrollView:

                    MDList:
                        OneLineIconListItem:
                            text: 'New Room'
                            on_release: manager.current = 'screen 2'
                            IconLeftWidget:
                                icon: 'theater'
                                
                        OneLineIconListItem:
                            text: 'Contacts'
                            IconLeftWidget:
                                icon: 'contacts'
                                
                        OneLineIconListItem:
                            text: 'Calls'
                            IconLeftWidget:
                                icon: 'cellphone-android'
                                
                        OneLineIconListItem:
                            text: 'Settings'
                            IconLeftWidget:
                                icon: 'settings'
                                
                        OneLineIconListItem:
                            text: 'FAQ'
                            IconLeftWidget:
                                icon: 'frequently-asked-questions'
                                
                        OneLineIconListItem:
                            text: 'Invite Friends'
                            IconLeftWidget:
                                icon: 'account-plus'
                                
                        OneLineIconListItem:
                            text: 'Toggle Theme'
                            IconLeftWidget:
                                icon: 'theme-light-dark'
'''


class EMC_WebmaApp(MDApp):
    def build(self):
        #self.theme_cls.primary_palette = 'DeepPurple'
        #self.theme_cls.theme_style = 'Dark'
        return Builder.load_string(KV)


EMC_WebmaApp().run()
Xyanight
  • 1,315
  • 1
  • 7
  • 10