【问题标题】:I have some problems when I work with the NavigationDrawer in KivyMD在 KivyMD 中使用 NavigationDrawer 时遇到一些问题
【发布时间】:2020-08-31 22:05:54
【问题描述】:

我想制作一个有 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"

【问题讨论】:

    标签: python kivy kivymd


    【解决方案1】:

    我这里测试了一下,标注工作正常。

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

    MDLabel:
        text: "Select your level"
    
        halign: "center"
    
        pos_hint: {"center_x": 0.5, "center_y": 0.8}
    
        font_style: "H5"
    

    【讨论】:

    • 我将间距改为83dp,空白消失了,但是当我抓住屏幕的一角并调整它的大小时,小部件不移动并且空白随着屏幕的高度而增加增加。
    • main.py: ` from kivymd.app import MDApp from kivy.lang import Builder class MainApp(MDApp): def build(self): return Builder.load_string(helper)`
    • 我改变了我的答案,关于改变大小时如何解决空白
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多