File "kivy/properties.pyx" - KeyError: 'stat_label' ((Its an id I defined))

279 views
Skip to first unread message

Henrik R.

unread,
Mar 31, 2022, 3:05:42 PM3/31/22
to Kivy users support
Hi!

I get this error, immediately when I try to run my app:
```
 Traceback (most recent call last):
   File "kivy/properties.pyx", line 961, in kivy.properties.ObservableDict.__getattr__
 KeyError: 'stat_label'
 
 During handling of the above exception, another exception occurred:
```

'stat_label' is an id on a Label. Those parts of the app worked before, and have only been changed slightly, so I don't understand what is causing this error.

Here is the relevant kv-rule:
```
<StatBox>:
id: stat_box # 'invisible', but not needed...!
MyScrollView:
ScalableLabel:
id: stat_label
markup: True
color: black # Text color
ScalableButton:
id: save_stats_button
on_release: root.button_pressed()
```

This is the Python class, and line 1210, in the class, that gives the second exception (see below):
```
class StatBox(BoxLayout):
...
...
self.ids.stat_label.text = my_data.cur_stats_page_text
```

The second exception:
```
   File "/mnt/4AF15A0435E762B4/mypython/GeoESP/main.py", line 1210, in init_statbox_strings
     self.ids.stat_label.text = my_data.cur_stats_page_text
   File "kivy/properties.pyx", line 964, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'
```

I find it hard to interpret Python/Kivy error messages. So any help would be quite appreciated. :-)

Henrik R.

unread,
Mar 31, 2022, 3:11:43 PM3/31/22
to Kivy users support
Sh*t! Is it impossible to include code in an appropriate way on this Google system...?

I will try a screen shot:
Python error 2022-03-31.png

Elliot Garbus

unread,
Mar 31, 2022, 4:32:49 PM3/31/22
to kivy-...@googlegroups.com

If you right-click in the Google text box and select paste as plain text, the indentation will be preserved.

 

My guess is that you are trying to access the id, “stat_label” in __init__(), prior to the ids dict being initialized.  You can instead use the Widget method on_kv_post(), rather than __init__().  The method on_kv_post() runs after the kv code for the widget has been processed so the ids are set.

See: https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=on_kv_post#kivy.uix.widget.Widget

--
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/94454d34-b3ab-41ea-8282-81677cdf8509n%40googlegroups.com.

 

Henrik R.

unread,
Mar 31, 2022, 5:41:49 PM3/31/22
to Kivy users support
Yes, that was it! Thank you!
I have had to use on_kv_post(self, base_widget) before, on your advice, but not in StatBox(BoxLayout), so I was a bit puzzled. :-)
Reply all
Reply to author
Forward
0 new messages