My question is the title. It is probably the same as this one, but I am not happy with the answer there or with my working minimal example below. That is because if I were to move the child I am making the call from one "nested layer" up or down (e.g. in my example: put the "special button" inside another Layout of the parent BoxLayout
) the callback function would not work anymore.
How to do this properly (and the intended kivy way)?
Minimal Example:
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.properties import ObjectProperty
Builder.load_string('''
<RootWidget>:
button1: b1
button2: b2
BoxLayout:
orientation: 'horizontal'
size: root.size
Button:
id: b1
text: 'I am the normal one'
SpecialButton:
id: b2
text: 'I am the special one'
<SpecialButton>:
on_release: root.clickityclick()
''')
class RootWidget(Widget):
button1 = ObjectProperty(None)
button2 = ObjectProperty(None)
class SpecialButton(Button):
def clickityclick(self):
self.parent.parent.button1.disabled = True ### <----- How to do this properly?
class MinimalExampleApp(App):
def build(self):
return RootWidget()
if __name__ == '__main__':
MinimalExampleApp().run()