Skip to content Skip to sidebar Skip to footer

Kivy Class In .py And .kv Interaction

I'm not fully grasping how classes in a python file and the kivy language interact. I'm currently modifying the Showcase example of Kivy to increase my understanding. File structur

Solution 1:

You can use the ScreenManager. Have a look here, I changed some of your code to provide an example of using the ScreenManager to seperate out the code for each screen into their own classes. If there are problems with this let me know.

main.py:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.properties import ObjectProperty


classTesty(Screen):

    ttext = 'Screen 2'#other codeclassScreenTwo(Screen):
    passclassManager(ScreenManager):

    testy = ObjectProperty(None)
    screen_2 = ObjectProperty(None)


classShowcaseApp(App):

    defbuild(self):
        return Manager(transition=FadeTransition())

if __name__ == "__main__":
    ShowcaseApp().run()

kv file:

<Testy>:BoxLayout:Button:text:root.ttexton_press:root.manager.current="screen_two"<ScreenTwo>:BoxLayout:Button:text:"Screen 1"on_press:root.manager.current="testy_screen"<Manager>:id:screen_managertesty:testyscreen_2:screen_2Testy:id:testyname:'testy_screen'manager:screen_managerScreenTwo:id:screen_2name:'screen_two'manager:screen_manager

Post a Comment for "Kivy Class In .py And .kv Interaction"