从导航抽屉 KivyMD 创建新屏幕

时间:2021-02-11 21:27:54

标签: python navigation-drawer kivymd

大家好,我是 KivyMD 的新手,正在开发我的第一个应用程序。基本上,我需要在单击导航抽屉中的内容时打开一个新屏幕。例如,我的导航抽屉上有一个“新建房间”按钮,我希望在单击它时打开一个新屏幕。

好的,这是我的代码

$testData = [
    '<a href=""><img/></a>',
    '<a href="#"><img/></a>',
    '<a class="button" href="#" rel="nofollow"><img/></a>',
    '<a href=""><img/></a>',
];

foreach ($testData as $test) {
    $d = new DOMDocument();
    $d->loadHTML($test, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    foreach ($d->getElementsByTagName('a') as $tag) {
        if (in_array(trim($tag->getAttribute('href')), ['#', ''], true)) {
            $tag->setAttribute('href', 'https://example.com');
        }
    }
    echo $d->saveHTML(), PHP_EOL;
}

这是我的字符串

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()

感谢帮助???

1 个答案:

答案 0 :(得分:0)

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()