I am attempting to bind a method to the text value of a spinner. It needs to be bound no later than when the TestScreen is displayed. This works if I don't use the ScreenManager, (eg if TestApp.build returns TestScreen instead of TestScreenManager). When TestApp.build returns TestScreenManager I get the following error when I reference self.ids in TestScreen.__init__
AttributeError: 'super' object has no attribute '__getattr__'
Test.py
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.app import App
class TestScreen(Screen):
def __init__(self, *args, **kwargs):
super(TestScreen, self).__init__(*args, **kwargs)
self.ids.test_spinner.bind(text=self.on_spinner_select)
def on_spinner_select(self, instance, data, *largs):
print("In on_spinner_select")
def print_spinner_value(self):
print(self.ids.test_spinner.text)
class TestScreenManager(ScreenManager):
pass
class TestApp(App):
def build(self):
#return TestScreen()
return TestScreenManager()
if __name__ == "__main__":
TestApp().run()
Test.kv
<TestScreen>:
name: "World Screen"
BoxLayout:
orientation: 'vertical'
Label:
text: "Name"
font_size: 30
BoxLayout:
Label:
text: "Active Selection"
size_hint_x: .5
Spinner:
id: test_spinner
text: "Value1"
values: ["Value1", "Value2"]
Button:
text: "Print spinner value"
on_press: root.print_spinner_value()
<TestScreenManager>:
TestScreen:
I have tried binding the method in the on_enter method but I get the same error. However, self.ids does work in the method print_spinner_value if I comment out the self.ids statement in the init function.
Currently I was able to find a work around by binding the function every time the spinner is pressed. But that doesn't seem like the best way to handle the problem
on_press: self.bind(text=root.on_spinner_select)
So my question is: How do I bind a method to the spinner on load while using the ScreenManager?