Home > Courses > Mobile Application Development (VU-CSS 223) > Kivy Screens, Navigation & State Management

Kivy Screens, Navigation & State Management

Subject: Mobile Application Development (VU-CSS 223)
Modern applications often contain multiple pages such as:
• Home Screen
• Login Screen
• Dashboard
• Settings Page
In Kivy, switching between screens is done using the ScreenManager and individual Screen widgets. This allows you to build multi-page interfaces.

KIVY SCREEN BASICS


Kivy provides two important classes:
1. ScreenManager: controls which screen is currently visible.
2. Screen: represents a single page or interface.

Basic Structure Example

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen

class HomeScreen(Screen):
    pass

class LoginScreen(Screen):
    pass

class MyScreenManager(ScreenManager):
    pass

class MyApp(App):
    def build(self):
        return MyScreenManager()

MyApp().run()


KV File

<MyScreenManager>:
    HomeScreen:
    LoginScreen:

<HomeScreen>:
    name: "home"
    BoxLayout:
        orientation: "vertical"
        Label:
            text: "Home Screen"
        Button:
            text: "Go to Login"
            on_press: app.root.current = "login"

<LoginScreen>:
    name: "login"
    BoxLayout:
        orientation: "vertical"
        Label:
            text: "Login Screen"
        Button:
            text: "Back to Home"
            on_press: app.root.current = "home"


By: Vision University

Comments

No Comment yet!

Login to comment or ask question on this topic


Previous Topic