lang add ids example

This commit is contained in:
qua-non 2013-10-23 20:54:04 +05:30
parent 3e5777ce2d
commit 18ff675879
1 changed files with 25 additions and 1 deletions

View File

@ -111,7 +111,7 @@ which has a child that is an instance of the
:class:`~kivy.uix.boxlayout.BoxLayout`. That BoxLayout further has two :class:`~kivy.uix.boxlayout.BoxLayout`. That BoxLayout further has two
children, instances of the :class:`~kivy.uix.button.Button` class. children, instances of the :class:`~kivy.uix.button.Button` class.
A python equivalent of this code could be: A python equivalent of this code caould be:
.. code-block:: python .. code-block:: python
@ -284,6 +284,30 @@ the function `check_status`. In contrast to this method you could also just pass
the `id` to the function that needs to use it, like in case of `f_but` in the the `id` to the function that needs to use it, like in case of `f_but` in the
code above. code above.
There is a simpler way to access the ids as defined in the kv language for example::
<MyBumHurts>
Button:
id: gentle_pats_are_good
text: 'press gently'
on_release: root.polite_smack()
Button:
id: masochist
text: 'make it red'
on_release: root.smack_hard()
In your python code::
class MyButtHurts(BoxLayout):
def polite_smack(self):
self.ids.gentle_pats_are_good.text = 'I like!, be gentle.'
self.ids.masochist.text = 'Is that all you've got? Make it red!'
def smack_hard(self):
self.ids.gentle_pats_are_good.text = 'OUCH!, be gentle.'
self.ids.masochist.text = 'Now that's more like it. Make it red!'
Templates Templates
--------- ---------