callback function in kv file

28 views
Skip to first unread message

Kazuya Haraguchi

unread,
Aug 22, 2016, 9:43:56 PM8/22/16
to kivy-...@googlegroups.com
Dear all,

I find that, in the following source code,
the property "value" of lbl is automatically binded to the function "on_value"
although I don't define "value" as a NumericProperty instance.

My question is, in general,
is the property defined in a kv file automatically binded to
the callback function "on_xxx"?
My kivy is v1.9.1.

/*--- main.py ---*/
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class MyRoot( BoxLayout ):
pass

class myApp( App ):
def build( self ):
return MyRoot()

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


/*--- my.kv ---*/
<MyRoot>:
orientation: 'horizontal'
Label:
id: lbl
text: '0'
value: 0
on_value:
self.text = str(self.value)
BoxLayout:
orientation: 'vertical'
Button:
text: 'Increase'
on_press:
lbl.value = lbl.value + 1
Button:
text: 'Reset'
on_press:
lbl.value = 0


WBR,
Kazuya HARAGUCHI
e-mail: kzy...@gmail.com

ZenCODE

unread,
Aug 23, 2016, 2:52:50 AM8/23/16
to Kivy users support
Yes, All properties get an automatic 'on_<property_name>' event.

Reply all
Reply to author
Forward
0 new messages