我在KivyMD中使用NavigationDrawer时遇到了一些问题

2024-04-26 00:04:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个应用程序,有3个不同的难度,并有一个NavigationDrawer更改自定义应用程序,例如:激活黑暗主题。当我添加导航抽屉时,当应用程序的大小改变时,窗口中的元素不会移动,工具栏上有一个奇怪的空白区域

This is thee window with a default size. Notice the blank space over the toolbar.

This happens when I resize the window

This is the window with the NavigationDrawer toggled

Also, when I reduce the size of the window to the minimum value, this happens with the buttons in the NavigationDrawer

这是kv代码,Python文件只包含一个空类:

Screen:
NavigationLayout:
    MDNavigationDrawer:
        id: nav_drawer
        MDRectangleFlatButton:
            text: "Screen 1"
            on_release: 
                screen_manager.current = "menu"
        MDRectangleFlatButton:
            text: "Screen 2"
            on_release: 
                screen_manager.current = "screen2"
            
    ScreenManager
        id: screen_manager
        Screen:
            name: "menu"
            BoxLayout:
                orientation: "vertical"
                spacing: "50dp"
            
            
                MDToolbar:
                    title: "Toolbar"
                    elevation: 11
                    left_action_items: [["menu", lambda x: nav_drawer.toggle_nav_drawer()]]
                    
                
                MDLabel:
                    text: "Select your level"
                    halign: "center"
                    pos_hint: {"center_x": 0.5, "center_y": 0.8}
                    font_style: "H5"
                    size_hint_y: None
                    hight: self.texture_size[1]
                    
                MDRectangleFlatButton:
                    text: "  Advanced  "
                    pos_hint: {"center_x": 0.5, "center_y": 0.7}
                    
                    
                    
                MDRectangleFlatButton:
                    text: "Intermediate"
                    pos_hint: {"center_x": 0.5, "center_y": 0.6}
                    
                    
                MDRectangleFlatButton:
                    text: "       Basic       "
                    pos_hint: {"center_x": 0.5, "center_y": 0.5}
                    
        Screen:
            name: "screen2"
            MDLabel:
                text: "Screen 2"

Tags: thetextpos应用程序sizewithwindowthis
1条回答
网友
1楼 · 发布于 2024-04-26 00:04:44

我在这里测试过,尺寸标注正常

空白是因为“间距:“50dp”,将其更改为80dp,并将MDLabel更改为:

MDLabel:
    text: "Select your level"

    halign: "center"

    pos_hint: {"center_x": 0.5, "center_y": 0.8}

    font_style: "H5"

相关问题 更多 >