首页 > 解决方案 > 如何在多个屏幕上保留 KivyMD 底部应用程序工具栏

问题描述

我试图将 KivyMD 工具栏保留在多个屏幕上,我之前在 stackoverflow 上进行了搜索,发现我可能需要创建一个类并继承它。问题:对吗?如果是,我将非常感激您是否可以制作班级样本,如果不是,我同样会感谢您的意见.. 谢谢。

这是我的 .py 文件

from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager, NoTransition
from kivy.core.window import Window

Window.size = (300, 500)


class Screen1(Screen):
    pass


class Screen2(Screen):
    pass


class TwoScreenApp(MDApp):
    def build(self):
        self.theme_cls.primary_palette = 'Gray'
        self.sm = ScreenManager(transition=NoTransition())
        self.sm.add_widget(Screen1(name='screen1'))
        self.sm.add_widget(Screen2(name='screen2'))

        return self.sm

    def change_screen(self, screen):
        self.sm.current = screen
    """I am using this self.sm method to link
    icon to screen2 until I find a better way"""


TwoScreenApp().run()

这是我的 .kv 文件

ScreenManager:
    Screen1:
    Screen2:

<Screen1>
    name: 'screen1'
    MDBoxLayout:
        md_bg_color: (240/255, 240/255, 240/255, 1)
        orientation: 'vertical'

        MDLabel:
            halign: 'center'
            text:
                """With the production of the Model T automobile,
                Henry Ford had an unforeseen and tremendous
                impact on American life. He became regarded
                as an apt symbol of the transition from an
                agricultural to an industrial America."""

        MDBottomAppBar:

            MDToolbar:
                icon: "account-circle"
                type: "bottom"
                left_action_items: [["arrow-right", lambda x: app.change_screen("screen2")], ["alpha-x-circle", lambda x: x]]
                right_action_items: [["alpha-y-circle", lambda x: x], ["arrow-left", lambda x: app.change_screen("screen1")]]
            elevation: 10

<Screen2>
    name: 'screen2'
    md_bg_color: (240/255, 240/255, 240/255, 1)

    MDBoxLayout:
        md_bg_color: (255/255, 255/255, 255/255, 1)
        orientation: 'vertical'

        MDLabel:
            halign: 'center'
            text:
                """The development of mass-production techniques, which
                enabled the company eventually to turn out a Model T
                every 24 seconds; the frequent reductions in the price
                of the car made possible by economies of scale; and
                the payment of a living wage that raised workers
                above subsistence and made them potential customers
                for, among other things, automobiles—these innovations
                changed the very structure of society."""

        MDBottomAppBar:

            MDToolbar:
                title: "Title"
                icon: "account-circle"
                type: "bottom"
                left_action_items: [["menu", lambda x: app.change_screen("screen1")]]

标签: kivypython-3.6kivy-languagekivymd

解决方案


推荐阅读