GUI-O Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to update a label

    Scheduled Pinned Locked Moved
    Frequently Asked Questions (FAQ)
    2
    4
    302
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lesept
      last edited by lesept

      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 as

      text = 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?

      L 1 Reply Last reply Reply Quote 0
      • L
        lesept @lesept
        last edited by lesept

        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)
        
        K 1 Reply Last reply Reply Quote 0
        • K
          kl3m3n @lesept
          last edited by kl3m3n

          @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

          L 1 Reply Last reply Reply Quote 0
          • L
            lesept @kl3m3n
            last edited by

            @kl3m3n Thanks for your answer. Yes this is (micro)python, used on an ESP32.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post