Skip to content

Instantly share code, notes, and snippets.

@kived
Last active May 31, 2016 21:09
Show Gist options
  • Save kived/0d2f95e3fe1dd116e43918991642e916 to your computer and use it in GitHub Desktop.
Save kived/0d2f95e3fe1dd116e43918991642e916 to your computer and use it in GitHub Desktop.
Kivy: referencing widgets
BoxLayout:
NavBar:
sm: screen_manager
ScreenManager:
id: screen_manager
#: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'
@kived
Copy link
Author

kived commented May 31, 2016

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