Last active
May 31, 2016 21:09
-
-
Save kived/0d2f95e3fe1dd116e43918991642e916 to your computer and use it in GitHub Desktop.
Kivy: referencing widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BoxLayout: | |
NavBar: | |
sm: screen_manager | |
ScreenManager: | |
id: screen_manager |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:import NoTransition kivy.uix.screenmanager.NoTransition | |
BoxLayout: | |
orientation: 'vertical' | |
NavBar: | |
sm: screen_manager | |
name: 'nav_bar' # if you actually need this, name is usually a Screen thing | |
ScreenManager: | |
id: screen_manager | |
transition: NoTransition() | |
SplashScreen: | |
name: 'splash_screen' # for a single-use screen, you can also set the name in the kv rule for the screen so you won't need it here | |
WeatherScreen: | |
name: 'weather_screen' | |
OperatorPanelScreen: | |
name: 'operator_panel_screen' |
You can still have separate kv files for other things, but at some point you need to put together the root widget. The root widget can be defined in a separate kv file - usually with the name of your app, as we will autoload this. For an app named ScreenManagerApp
we will automatically look for a file named screenmanager.kv
in the same folder. If you wanted to be more dynamic about which screens are added, just can them out of the root widget kv and add the screens in Python. The app kv file is loaded before App.build()
is called.
def build(self):
self.root.ids.screen_manager.add_widget(SplashScreen())
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The reason I was doing what I was doing was so that I could keep modules of code. I know my app will grow quickly with new functionality.
I'm trying to do:
and then load everything at startup. Sort of like Django does, if you're familiar with that. And I can keep my modules, well modular ... LOL
I had it all working with a single KV file and single class... but that will be really hard to maintain going into the future.