Reputation: 23
I have defined my screens in .kv file, and I can access them without any problem when using ie. on_release: app.root.current = 'main' in .kv. But I have a problem when Buttons are created dynamically in python, what is equivalent to on_release: app.root.current = 'main' in python? Because I cant make it recognize app.root.
Upvotes: 2
Views: 1192
Reputation: 14794
You can access the current App
in Python by calling App.get_running_app()
. So, in other words:
from kivy.app import App
def change_screen(*args):
App.get_running_app().root.current = 'main'
from kivy.uix.button import Button
btn = Button(text='abc')
btn.bind(on_press=change_screen)
Upvotes: 3