fccoelho
fccoelho

Reputation: 6204

Updating a Label widget in Kivy

I have a Label on Kivy defined in KV like this:

Label:
    id: vol
    text: '[color=#3333ff]Volume: {0:8.2f}[/color]'
    markup: True
    size_hint_x: 0.2

Every few seconds, I update it with code that look like this:

self.vol.text = self.vol.text.format(tick['volume'])

However the text does not get updated on the app, staying as I first set it.

What is required to have the Label be redrawn after I change its text content?

Upvotes: 0

Views: 213

Answers (1)

zeeMonkeez
zeeMonkeez

Reputation: 5177

Once the first replacement has taken place, there is no replacement field left to take the updated value. Instead, try something like this:

self.vol.text = '[color=#3333ff]Volume: {0:8.2f}[/color]'.format(tick['volume'])

If you want, you can subclass Label and add a custom update function, so that knowledge about the formatting string resides with the label, and the update function can be called from different places.

Upvotes: 1

Related Questions