Reputation: 87
How do I access img_path
and img
attributes of class(screen) E1
inside Guide
? I'm doing it currently as shown in the code below, but it throws an error saying AttributeError: 'super' object has no attribute '__getattr__'
.
I read a number of answers on this and figured that I have to declare these as StringProperty()
maybe, but they all had a separate .kv
file where they defined the screens so I couldn't figure out how to do the same with my piece of code.
class E1(GridLayout):
...
...
self.img_path = "./Images/e1.jpg"
self.img = Image(source = self.img_path)
...
...
class GuideOP(GridLayout):
...
...
self.img_path = app.screen_manager.get_screen("E1").ids.img_path.get()
self.img = app.screen_manager.get_screen("E1").ids.img.get()
...
...
class MyApp(App):
def build(self):
self.screen_manager = ScreenManager()
self.e1_page = E1()
screen = Screen(name = "E1")
screen.add_widget(self.e1_page)
self.screen_manager.add_widget(screen)
self.guide_page = GuideOP()
screen = Screen(name = "GuideOP")
screen.add_widget(self.guide_page)
self.screen_manager.add_widget(screen)
return self.screen_manager
Upvotes: 0
Views: 35
Reputation: 38837
If you are not using a kv
file, then you cannot use ids
. That is likely the source of the error message.
Assuming that
self.guide_page = GuideOP()
is actually meant to use the
class Guide(GridLayout)
Then, I think you can try:
self.img_path = app.screen_manager.get_screen("E1").children[0].img_path
self.img = app.screen_manager.get_screen("E1").children[0].img
I haven't tested this code, but I think it should work. Note that the E1
Widget
is a child of the Screen
named E1
. Thus the use of children[0]
. This assumes that there are no other children
of that Screen
.
Upvotes: 1