kivy - 如何在多个屏幕上保留 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")]]
解决方案
推荐阅读
- javascript - 如何正确地将在 React 中以状态传递的 Date 对象放入 datepicker?
- java - SolrHealthIndicator 没有弃用 CompositeHealthIndicator
- javascript - 我有一个很长的 json,我希望在页面加载时只显示四个,并在用户单击投资链接时显示其余部分
- oracle - Oracle (XE) & SQL-Developer:如何找出正在使用的时间/日期/时间戳格式?
- c# - 最后用空值排序
- lotus-notes - Lotusscript - 使用 ArrayGetIndex 时类型不匹配
- c++ - 如何使用 std::enable_if 元函数实现类模板函数?
- java - 我们如何加载其他语言数据而不是英语数据?
- typescript - @types/express 是否有任何文档?
- mysql - 如何仅在 MySQL 中使用日期值但 VARCHAR 数据类型的列中替换文本字符?