Kivy App with Real-Time Color Selection

  • Share this:

Code introduction


Create a Kivy application where the user can select a color using the ColorSelector component, and the label will update in real-time to display the currently selected color.


Technology Stack : Kivy

Code Type : Kivy App

Code Difficulty : Intermediate


                
                    
def random_color_widget(color_name):
    from kivy.app import App
    from kivy.uix.label import Label
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.colorselector import ColorSelector

    class RandomColorApp(App):
        def build(self):
            layout = BoxLayout(orientation='vertical')
            self.color_label = Label(text=f'Current Color: {color_name}')
            layout.add_widget(self.color_label)
            color_selector = ColorSelector()
            color_selector.bind(color=self.update_color)
            layout.add_widget(color_selector)
            return layout

        def update_color(self, instance, value):
            self.color_label.text = f'Current Color: {value}'

    return RandomColorApp().run()                
              
Tags: