Home > OS >  i can find the problem ScreenManager in kivymd
i can find the problem ScreenManager in kivymd

Time:03-23

can you plz tell me the problem in this code forsome reason it is not showing anything in screen

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'''

CodePudding user response:

According to kivy documentation a class name in kvlang should be capitalized in order to avoid syntax error.

Thus the screen named page_f can be Page_f or any valid name following above mentioned rule. You should also make this changes in python.

As a side note, since you've already defined the root (ScreenManager) in kvlang you don't need the following code block anymore.

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