How to update a label
-
Hi,
I'd like to update the text of a label using values coming from sliders. I create a text variable containing the content I want to show in the label, such astext = f'{red} {green} {blue}'
How can I display this text in my label? It seems I can only use fixed texts and not dynamic texts.
If I try
ble.write("@text TXT:text\r\n")
the label only displays 'text', instead of something like '125, 34 56'
More generally, can I use the color values from the sliders to change the BCG of another widget?
-
I think I found it: just make a composite string for the entire ble message
text = f'@text TXT:"{red} {green} {blue}"\r\n' ble.write(text)
-
@lesept Hi,
glad you've found a solution. Is this Python?
You could also concatenate strings, e.g. in C++ (assuming standard library):
#include <string> ... auto r = std::to_string(125); auto g = std::to_string(34); auto b = std::to_string(56); std::string str = "@text TXT:\"" + r + "," + g + "," + b + "\"\n\r"; // str is: @text TXT:"125,34,56"
In Python this would be even simpler...
Best regards,
kl3m3n -
@kl3m3n Thanks for your answer. Yes this is (micro)python, used on an ESP32.