From 18ff675879fcaa28f25ccaac90267d9082c60d52 Mon Sep 17 00:00:00 2001 From: qua-non Date: Wed, 23 Oct 2013 20:54:04 +0530 Subject: [PATCH] lang add ids example --- doc/sources/guide/lang.rst | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/sources/guide/lang.rst b/doc/sources/guide/lang.rst index e1adec66b..88ffe523d 100644 --- a/doc/sources/guide/lang.rst +++ b/doc/sources/guide/lang.rst @@ -111,7 +111,7 @@ which has a child that is an instance of the :class:`~kivy.uix.boxlayout.BoxLayout`. That BoxLayout further has two 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 @@ -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 code above. +There is a simpler way to access the ids as defined in the kv language for example:: + + + 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 ---------