使用Kivy / KivyMD

时间:2019-08-20 16:26:50

标签: python kivy

我正在尝试在Kivy中设计一个应用程序,并希望使用导航抽屉创建一个侧面菜单,单击该菜单即可显示。我还在ScrollView中添加了手风琴,以便用户可以从下拉菜单中选择项目,但是我遇到以下问题:

  1. 我无法使手风琴出现在导航抽屉的顶部。

  2. 手风琴项目本身似乎被迫置于手风琴的右侧,而不是居中或左侧。

  3. 其中一个手风琴总是从打开位置开始,但我希望它们全部开始关闭

我尝试过的事情

1&2。尝试使用“ pos_hint”将小部件位置设置为无效

  1. 尝试在两个手风琴上将折叠值设为true,但未成功。

相关的Python代码

import kivy
import kivymd
kivy.require('1.11.1')
from kivymd.theming import ThemeManager
from kivymd.menus import MDDropdownMenu
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty

rc_gui = None

class RcGUIApp(App):

    theme_cls = ThemeManager()
    title='RUCES'

    def build(self):
        self.theme_cls.theme_style = "Light"
        self.sm = ScreenManager()
        self.sm.add_widget(ResultPages(name="result_pages"))
        return self.sm


class ResultPages(Screen):  

    grid = ObjectProperty(None)

    menu_items = [
                  {'viewclass': 'MDMenuItem', 'text': 'New', 'id': 'new'},
                  {'viewclass': 'MDMenuItem', 'text': 'Save'},
                  {'viewclass': 'MDMenuItem', 'text': 'Load'},
                  {'viewclass': 'MDMenuItem', 'text': 'Export'}
                 ]
    def buildOptionsMenu(self):

        self.options_menu = MyDropdownMenu(items=self.menu_items, pos_hint= {'top': 1, 'right': 1})
        self.options_menu.open(self)

#Main function
def main():

        global rc_gui
        rc_gui = RcGUIApp()
        rc_gui.run()

相关kv代码: (很抱歉,使用8个空格缩进而不是4个缩进,Spyder一直告诉我这是必需的)

<ResultPages>:

    nav_layout: nav_layout
    main_grid: main_grid
    grid: Grid             

    NavigationLayout:
            id: nav_layout
            grid: Grid
            main_grid: main_grid
            MDNavigationDrawer:
                    id: nav_drawer_right
                    NavigationDrawerToolbar:
                            title: "Actions"

                    MDAccordion:

                            size_hint_y: 1

                            orientation: 'vertical'

                            MDAccordionItem:
                                    title: "Segment"
                                    pos_hint: {'top': 1}
                                    orientation: 'vertical'
                                    collapse: True

                                    ScrollView:

                                            GridLayout:

                                                    pos_hint: {'left': 1}

                                                    row_force_default: True
                                                    row_default_height: 40
                                                    cols: 1
                                                    height: self.minimum_height
                                                    size_hint: 1, None 

                                                    orientation: 'vertical'
                                                    MDFlatButton:
                                                            icon: 'checkbox-blank-circle'
                                                            text: "Direct Costs"
                                                    MDFlatButton:
                                                            icon: 'checkbox-blank-circle'
                                                            text: "Direct Labour"
                                                    MDFlatButton:
                                                            icon: 'checkbox-blank-circle'
                                                            text: "Crew Types"
                                                    MDFlatButton:
                                                            icon: 'checkbox-blank-circle'
                                                            text: "Asset Allocation"

                            MDAccordionItem:
                                    id: filler
                                    collapse: True
                                    title: "Report"

                                    ScrollView:

                                            GridLayout:

                                                    row_force_default: True
                                                    row_default_height: 40
                                                    cols: 1
                                                    height: self.minimum_height
                                                    size_hint: 1, None 

                                                    MDFlatButton:
                                                            icon: 'checkbox-blank-circle'
                                                            text: "Tasks"
                                                    MDFlatButton:
                                                            text: "Calculate"
                                                    MDFlatButton:
                                                            text: "View/Print"

            GridLayout:
                    cols: 1
                    size_hint_x: 1
                    spacing: 10
                    id: main_grid
                    nav_box: nav_box

                    BoxLayout:
                            orientation: 'vertical'
                            id: nav_box
                            toolbar: toolbar
                            grid: Grid
                            Toolbar:

                                    size_hint_y: .10
                                    id: toolbar
                                    title: 'Parts Estimate'
                                    md_bg_color: app.theme_cls.primary_color
                                    background_palette: 'Primary'
                                    background_hue: '500'
                                    left_action_items: [['menu', lambda x: root.nav_layout.toggle_nav_drawer()]]
                                    right_action_items: [['dots-vertical', lambda x: root.buildOptionsMenu()]]

这是运行代码时得到的,可以忽略后台的表。 Picture of output

感谢您的帮助!

0 个答案:

没有答案