It’s not clear to me what you are trying to achive.
You have MainScreen.state declared in 2 places:
class MainScreen(Screen):
state = ObjectProperty() # This is declaring root.state
is redundant with:
<MainScreen>:
state: app.state # this is declaring root.state, and initializing it to the value in app.state
If you comment out
# state: app.state
And make the object property a list property
class MainScreen(Screen):
state = ListProperty() # This is declaring root.state
Then the test will behave as expected.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/53ddd8de-b07b-4bb0-a39d-6ddf7ed0948e%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.
You can access app variables from anywhere in KV by referring to them as:
inside python you can use the App method get_running_app() to access them.
def my_code():
app_ptr = App.get_running_app()
app_ptr.name = ‘I am writing this string to app.name”
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bd8df852-e0fe-4d10-9ef0-47bbbca1360e%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/bd8df852-e0fe-4d10-9ef0-47bbbca1360e%40googlegroups.com.
I don’t think I know enough about your apps structure, but in general no, I don’t think you are fighting kivy’s architecture.
Kivy is object oriented, occasionally you will have challenges on how to access data between classes. Using properties or variables in App, is a reasonable solution.
The widget tree also provides a rich syntax for reaching across objects and screens.
Here is a line from a piece of code I’m working on:
e = App.get_running_app().root.ids.sm.get_screen('editor').ids.editor
There is fantastic development/debug/kivy exploration tool called the inspector that is useful for exploring the widget tree.
From the command line: python your_main.py -m inspector
Read about it here: https://kivy.org/doc/stable/api-kivy.modules.html#module-kivy.modules
Hope this helps. Kivy is a complex system, there is a learning curve, but also good docs. If you have any questions don’t hesitate to post to the forum.
Good Luck!
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f8f49adc-a816-4658-9651-50a74b794885%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f8f49adc-a816-4658-9651-50a74b794885%40googlegroups.com.