Kivy App with Random Number Labels

  • Share this:

Code introduction


This code creates a Kivy application that includes multiple labels with a random number. Each label is added to a vertical layout.


Technology Stack : Kivy

Code Type : Kivy app

Code Difficulty : Intermediate


                
                    
import random
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.core.window import Window

def random_widget_app():
    class RandomWidgetApp(App):
        def build(self):
            layout = BoxLayout(orientation='vertical')
            for _ in range(random.randint(1, 5)):
                label = Label(text=f"Random Label {_}")
                layout.add_widget(label)
            return layout

    RandomWidgetApp().run()                
              
Tags: