Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Properties

In Kivy are special types of class attributes that provide additional features like type checking, automatic updating, and event firing when their values change


Basic Properties

Kivy provides several types of properties, such as StringProperty, NumericProperty, BooleanProperty, and more. Properties are used to store widget state and can be dynamically updated.


Example: Using Properties


from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.slider import Slider
from kivy.properties import NumericProperty

class MyWidget(BoxLayout):
    value = NumericProperty(0)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'vertical'
        self.label = Label(text=str(self.value))
        self.slider = Slider(min=0, max=100, value=self.value)
        self.slider.bind(value=self.on_value_change)
        self.add_widget(self.label)
        self.add_widget(self.slider)

    def on_value_change(self, instance, value):
        self.value = value
        self.label.text = str(self.value)

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

if __name__ == '__main__':
    MyApp().run()

            

In this Example


Common Property Types

StringProperty Stores a string value.

NumericProperty Stores a numeric value (int or float).

BooleanProperty Stores a boolean value.

ListProperty Stores a list.

DictProperty Stores a dictionary.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML 5

Python

java

C++

C

JavaScript

Campus Learning

C

C#

java