In Kivy are special types of class attributes that provide additional features like type checking, automatic updating, and event firing when their values change
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.
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()
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.