从NavigationDrawer在屏幕内打开Kivy设置

时间:2019-11-21 10:29:26

标签: python kivy

我想从kivymd导航抽屉中打开屏幕内的kivy设置。默认设置仅在新窗口中打开,该窗口完全忽略应用程序的颜色主题。关于如何使设置成为屏幕管理器子级的任何建议?

这是guiApp.py:

from kivy.app import App
import kivymd
from kivymd.theming import ThemeManager
from kivy.uix.settings import Settings, SettingsWithSidebar

class guiApp(App):
    theme_cls = ThemeManager()
    theme_cls.primary_palette = 'BlueGray'
    theme_cls.theme_style = 'Light'

    def build(self):
        self.settings_cls = SettingsWithSidebar

guiApp().run()

和gui.kv:

NavigationLayout:
     MDNavigationDrawer:
          NavigationDrawerSubheader:
               text: 'Operation Menu'

          NavigationDrawerIconButton:
               icon: 'information-outline'
               text: 'Introduction'
               on_release: screen_manager.current = 'screen_info'

          NavigationDrawerIconButton:
               icon: 'settings'
               text: 'Settings'
               on_release: screen_manager.current = 'screen_settings'
               on_release: app.open_settings()

BoxLayout:
          orientation: 'vertical'
          MDToolbar:
               title: 'My GUI'
               md_bg_color: app.theme_cls.primary_color
               left_action_items: [['menu', lambda x: root.toggle_nav_drawer()]]

          ScreenManager:
               id: screen_manager

               Screen:
                    name: 'screen_info'

                    MDLabel:
                         text: 'This page will be used for information on how to use the App '
                         theme_text_color : 'Hint'
                         valign: 'middle'
                         halign: 'center'
               Screen:
                    name: 'screen_settings'
                    BoxLayout:

1 个答案:

答案 0 :(得分:0)

您可以使用app.create_settings()代替设置app.open_settings()来获取设置小部件,您可以将其直接附加到屏幕

on_start 方法添加到 guiApp

[...]
class guiApp(App):
    [...]

    def on_start(self):
        s = self.create_settings()
        self.root.ids.settings_content.add_widget(s)

并为您的 screen_settings

的BoxLayout赋予一个ID
[...]
Screen:
    name: 'screen_settings'
    BoxLayout:
        id: settings_content