Skip to content
Advertisement

I can’t update the content of a Kivy label from Python

I state that this is the first time I use Kivy. The code I attached works, the only problem is that the lbl label does not update automatically but only if I press the update button. In practice, if I call the update_lbl function via the “update” button it works, when it is called automatically by unpacking_msg it does nothing.

JavaScript

Here is the Kivy file:

JavaScript

I really appreciate any other helpful advice! I am not an expert as you can see.

Advertisement

Answer

The problem is that your code:

JavaScript

is creating a new instance of MainApp and calling its update)lbl() method. However, that new instance of MainApp is not the instance that you see on the screen. You must call the update_lbl() method of the running App. You can do that by using the get_running_app() method. See the documentation. Try this replacement for the above line:

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