Skip to content
Advertisement

Kivy: AttributeError: ‘…’ object has no attribute ‘…’, but it has

I have this TaskTemplate with some Buttons, TexInput, etc. I will put just a piece of code for an easy understanding.

JavaScript
JavaScript

If I use TaskTemplate as root class it works, I can change the state of the CheckBox with that parameter.
If I add TaskTemplate here:

JavaScript

I get this error which has no end:

JavaScript

Advertisement

Answer

Your update_state is just an instance variable of TaskTemplate. So using state: root.update_state in your kv just sets the initial state of the CheckBox. Changing that variable will have no effect on the CheckBox. If you want the CheckBox to reflect changes to the value of update_state, then you have two choices.

  1. Write python code that will update the CheckBox whenever you change the value of update_state.
  2. Change update_state to a Property. Then kv will add the binding to update the CheckBox whenever update_state is changed.

In order to implement #2 above simply change:

JavaScript

to:

JavaScript

Note: unless you have something more planned for TaskTemplate, there is no need for it to extend Button.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement