callback function in kv file

28 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Kazuya Haraguchi

ungelesen,
22.08.2016, 21:43:5622.08.16
an 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

ungelesen,
23.08.2016, 02:52:5023.08.16
an Kivy users support
Yes, All properties get an automatic 'on_<property_name>' event.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten