我可以在 kivymd 中找到问题 ScreenManager

i can find the problem ScreenManager in kivymd

你能告诉我问题吗 出于某种原因,在这段代码中它没有在屏幕上显示任何内容

from kivymd.app import MDApp
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder

kv='''

ScreenManager:
    page_f:
    page_s:
        
<page_f>:
    name: 'page_f'
    MDFlatButton:
        text: 'go'
        pos_hint:{'center_x':.5,'center_y':.5}
        on_press: root.manager.current = 'page_s'
<page_s>:
    name: 'page_s'
    MDFlatButton:
        text: 'back'
        pos_hint:{'center_x':.5,'center_y':.5}
        on_press: root.manager.current = 'page_f'
'''

class page_f(Screen):
    pass


class page_s(Screen):
    pass

sm = ScreenManager()
sm.add_widget(page_f(name='page_f'))
sm.add_widget(page_s(name='page_s'))

class main(MDApp):
    def build(self):
        return Builder.load_string(kv)

if __name__ == '__main__':
    main().run()

'''please ignore this this is becouse of a error iam gating while uploding question'''

根据 kivy documentationkvlang 中的 class 名称应大写以避免语法错误。

因此名为 page_f 的屏幕可以是 Page_f 或遵循上述规则的任何有效名称。您还应该在 python.

中进行此更改

附带说明一下,因为您已经在 kvlang 中定义了根 (ScreenManager),所以您不再需要以下代码块。

sm = ScreenManager()
sm.add_widget(page_f(name='page_f'))
sm.add_widget(page_s(name='page_s'))