【问题标题】:Python Transparent KivyMD Navigation DrawerPython透明KivyMD导航抽屉
【发布时间】:2020-11-21 15:09:12
【问题描述】:

我正在尝试对我的应用(数字规划器)应用一些更改,其中之一是能够在 MDNavigationDrawer 中切换屏幕,但我有两个问题:

  1. 导航。抽屉是透明的。我尝试将其不透明度设置为 1 - 无效。
  2. 导航。抽屉似乎在屏幕“下方”。如果导航上按钮的位置。抽屉和屏幕上的按钮匹配,按下的按钮是屏幕上的那个,而不是导航上的那个。抽屉。

MDNavigationDrawer 的外观如下

这是我的一些 Kivy 代码:

BoxLayout:
    orientation: "vertical"

    manager: manager
    nav_drawer: nav_drawer

    MDToolbar:
        id: tb
        type: "top"
        title: "VPlanner"
        left_action_items: [["menu", lambda x: nav_drawer.set_state()]]
        right_action_items: [["settings", lambda x: app.open_settings()]]

    NavigationLayout:
        x: tb.height
    
        MDNavigationDrawer:
            id: nav_drawer

            ContentNavigationDrawer:    

        ScreenManager:
            id: manager

            menu_window: menu_window
            stats_window: stats_window
            history_window: history_window

            MenuWindow:
                id: menu_window

            StatsWindow:
                id: stats_window

            HistoryWindow:
                id: history_window


<ContentNavigationDrawer>:
    cols: 1
    orientation: "vertical"

    OneLineListItem:
        text: "Menu"

        size_hint: 1, None
        on_release: 
            app.root.nav_drawer.set_state("close")
            app.root.manager.current = "menu"

    OneLineListItem:
        text: "Statistics"

        size_hint: 1, None
        on_release: 
            app.root.nav_drawer.set_state("close")
            app.root.manager.current = "stats"

    OneLineListItem:
        text: "History"

        size_hint: 1, None
        on_release: 
            app.root.nav_drawer.set_state("close")
            app.root.manager.current = "history"

这是我的一小段 Python 代码:

# there were lots of lines in each class representing screens,
# so I only left the ContentNavigationDrawer class, which is,
# as you already figured it out, supposed to represent content
# displayed in the MDNavigationDrawer.


class ContentNavigationDrawer(GridLayout):
    pass

提前致谢!

【问题讨论】:

    标签: python python-3.x kivy kivymd


    【解决方案1】:

    问题

    Navigation Drawer 看起来是透明的,因为它被放置在 ScreenManager 之前。

    解决方案

    MDNavigationDrawer: 放在 ScreenManager:

    之后

    片段

    NavigationLayout:
        x: tb.height
    
        ScreenManager:
            id: manager
    
            ...
            HistoryWindow:
                id: history_window
    
        MDNavigationDrawer:
            id: nav_drawer
    
            ContentNavigationDrawer:
    

    输出

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-14
      • 1970-01-01
      • 2021-05-20
      • 2022-12-24
      • 2014-12-31
      相关资源
      最近更新 更多