You can download this code by clicking the button below.
This code is now available for download.
This code creates a Kivy ScreenManager, generates a random screen, and displays a welcome message on the screen.
Technology Stack : Kivy, ScreenManager, Screen, Builder, random
Code Type : The type of code
Code Difficulty : Intermediate
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
from random import choice
def create_random_screen():
screen_manager = ScreenManager()
screen_name = choice(["Home", "Settings", "Profile"])
screen = Screen(name=screen_name)
screen.add_widget(Builder.load_string('''
Label:
text: "Welcome to the {} screen!"
size_hint: 0.5, 0.5
pos_hint: {"center_x": 0.5, "center_y": 0.5}
'''.format(screen_name)))
screen_manager.add_widget(screen)
return screen_manager