The White Rabbit

It is better to be approximately right than precisely wrong. (Warren Buffet)

Published on Monday, 30 March 2020

Tags: kivy3 oop2

AttributeError: 'super' object has no attribute '__getattr__'

How did I solve this AttributeError in Kivy.


Error

File "gui.py", line 31, in init self.ids.col_box_1.add_widget(Button(text=col)) File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.getattr AttributeError: 'super' object has no attribute 'getattr'

Solution

In my code I had these lines causing the error

...
class test(Screen):
    def __init__(self):
        for col in df.columns:
            self.ids.col_box_1.add_widget(Button(text=col))
...

I solved it by adding the **kwargs as parameter of _init_ and executing the super.(myclassname, self).__init(**kwargs) as first command inside it.

Here the modified working code:

...
class test(Screen):
    def __init__(self, **kwargs):
        super(test, self).__init__(**kwargs)
        for col in df.columns:
            self.ids.col_box_1.add_widget(Button(text=col))
...

Still not solved?

Try the following:

  • Make sure that the class rule in the .kv file has the same name as the corresponding class defined in your .py file. Considering the previous example, if the class is called "test", than you should have a "<test>:" in your .kv file.
  • How did you define your widgets ids? If you do it in your .kv file, don’t set the id as a string but remove the quotation marks (i.e.: id: "someid" is WRONG, instead id: someid is fine). If you defined your ids in the Python code, they will not be accessible using the self.ids property, since it’s a dictionary containing the ids parsed in the .kv file. References to your widgets dinamically created in your Python code can be obtained by storing them into a variable.

To know more about the structure of a Kivy program, consider reading this introduction.