【发布时间】:2021-10-02 20:17:16
【问题描述】:
我做了一个很基础的App,底部有KivyMD App bar。我在尝试使用工具栏图标切换屏幕时遇到问题。
这是我的 main.py 文件(请多多包涵,我的代码在实施一些我找到的解决方案时有点聚集,但没有奏效)
from kivymd.app import MDApp
from kivy.uix.screenmanager import Screen, ScreenManager
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'
sm = ScreenManager()
sm.add_widget(Screen1(name='screen1'))
sm.add_widget(Screen2(name='screen2'))
return sm
def callback(self, screen):
self.current = screen
# root.manager.transition.direction = 'left'
# root.manager.current = 'screen2'
# link icon to screen2
TwoScreenApp().run()
这是我的 .kv 文件
ScreenManager:
Screen1:
Screen2:
<Screen1>
name: 'screen1'
MDBoxLayout:
md_bg_color: (255/255, 255/255, 255/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: root.manager.callback("screen1")]]
right_action_items: [["arrow-left", lambda x: x]]
elevation: 10
<Screen2>
name: 'screen2'
md_bg_color: (200/255, 200/255, 200/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: x]]
我将不胜感激,谢谢!
【问题讨论】:
标签: python python-3.x kivy kivy-language kivymd