Reputation: 2982
My kivy app has nearly 100 screens. I am using ScreenManager to load the screens on startup (code below), but this is causing the app to take 30 seconds to load. Is there a more efficient way to handle screens in kivy, so screens only load when they are needed instead of loading all screens at app launch? I've seen kivy's switch_to(), but I'm unsure of how to use this instead of the on_press: root.manager.current = 'login'
in a Button widget, for instance, or if switch_to() is even appropriate for this use case. What is the best practice for efficiently loading and switching between screens in a kivy app that has many screens?
class LoginScreen(Screen):
...
class GameApp(App):
sm = ScreenManager()
def build(self):
self.sm.add_widget(LoginScreen(name='login'))
self.sm.add_widget(SignUpScreen(name='signup'))
...
Upvotes: 2
Views: 1388
Reputation: 29450
My kivy app has nearly 100 screens. I am using ScreenManager to load the screens on startup (code below), but this is causing the app to take 30 seconds to load. Is there a more efficient way to handle screens in kivy, so screens only load when they are needed instead of loading all screens at app launch?
Yes, code the screen caching yourself, e.g. with your own method that does whatever you want (e.g. unloading screens if too many are present, creating the new screen if it doesn't exist yet, showing the new screen by setting .current
etc.)
I've seen kivy's switch_to()
switch_to()
just takes a new screen, removes the old one entirely, and shows the new one (unlike just setting .current
, which doesn't remove the old one entirely). You might find it convenient, but it doesn't directly solve your problem.
Upvotes: 3