The issue: The kv code has not yet been processed when the __init__ code is executed. This means the ids dict has not yet been populated. This results in the error.
Instead of using __init__(), use on_kv_post(). This is executed after the kv code has been processed.
class WelcomeScreen(Screen):
def on_kv_post(self, base_widget):
# super(Screen,self).__init__(**kwargs)
box1 =self.ids.box
box1.add_widget(FigureCanvasKivyAgg(plt.gcf()))
on_kv_post is a Widget event. See: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=on_kv_post#kivy.uix.widget.Widget
This approach will work if you want to create the screen once when the screen is instanced, much like __init__(). If you need to create a plot each time the screen is displayed you could use the Screen event on_pre_enter. See: https://kivy.org/doc/stable/api-kivy.uix.screenmanager.html?highlight=screenmanager#kivy.uix.screenmanager.Screen
From: Esra Issam
Sent: Wednesday, August 24, 2022 3:54 AM
To: Kivy users support
Subject: [kivy-users] AttributeError: 'super' object has no attribute '__getattr__'
Hello
I am trying to add a chart to a screen using the __init__ because I want it to appear as soon as the screen appear, and I have more than one screen.
I get this error when I run the code and I could not figure out the reason of it.
any help please?
error:
python code:
kv code:
if you need please find the attachment
thank you in advanced
--
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/72a330e6-f35a-4bd7-9088-c67d072978cfn%40googlegroups.com.