抽屉出现在kivymd中的其他小部件下方

问题描述 投票:0回答:1

导航抽屉我的导航抽屉出现在其他小部件下方。如果有人知道请回答它,我不明白我在做什么错,因为我一直在努力。我希望导航抽屉在应用程序中的所有其他小部件上显示这是我的.py文件

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.widget import Widget
from kivymd.app import MDApp


class ContentNavigationDrawer(BoxLayout):
    def hllo(self):
        print('Hello though')


class MainScreen(Widget):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)


class MainsApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.title = "Story A Day"
        self.theme_cls.theme_style = "Dark"

    def build(self):
        self.theme_cls.primary_palette = "Blue"  # "Purple", "Red"


if __name__ == '__main__':
    MainsApp().run()

和我的.kv文件

Screen:

    NavigationLayout:

        ScreenManager:

            Screen:

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: "Story A Day"
                        elevation: 10
                        left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

                    Widget:


        MDNavigationDrawer:
            id: nav_drawer
            swipe_distance: 10

            ContentNavigationDrawer:
                id: content_drawer

    MainScreen:
        id: ma_sr


<ContentNavigationDrawer>
    background_color: 2, 3, 4, 5
    orientation: "vertical"
    padding: "8dp"
    spacing: "8dp"

    AnchorLayout:
        anchor_x: "left"
        size_hint_y: None
        height: avatar.height

        Image:
            id: avatar
            size_hint: None, None
            size: "56dp", "56dp"
            source: "data/logo/kivy-icon-256.png"

    Button:
        background_color: 9, 2, 4, 1
        text: 'You Can'
        on_release: root.hllo()

    MDRaisedButton:
        text: 'Click Me'
        on_release: print('Hell')

    MDLabel:
        text: "Welcome"
        font_style: "Button"
        size_hint_y: None
        height: self.texture_size[1]

    MDLabel:
        text: 'Story A Day'
        font_style: "Caption"
        size_hint_y: None
        height: self.texture_size[1]

    ScrollView:


<MainScreen>:
    Button:
        text: 'Hy'
kivy navigation-drawer python-3.7 kivy-language
1个回答
0
投票

也许尝试将其放在ScreenManager之前?

Screen:

    NavigationLayout:

        MDNavigationDrawer:
            id: nav_drawer
            swipe_distance: 10

            ContentNavigationDrawer:
                id: content_drawer

        ScreenManager:

            Screen:

                BoxLayout:
                    orientation: 'vertical'

                    MDToolbar:
                        title: "Story A Day"
                        elevation: 10
                        left_action_items: [['menu', lambda x: nav_drawer.set_state()]]

                    Widget:

    MainScreen:
        id: ma_sr

...
© www.soinside.com 2019 - 2024. All rights reserved.