Skip to content
Advertisement

How do we dynamically change the text in label widget of Tkinter according to the change of subscribed topic message?

I wanted to change the text of my label according to the topic message to which my node subscribes. But the problem is that the text in the label is not changing with the change of topic message. A portion of my code is given below:(I used the code to dynamically change the text in the label from https://bytes.com/topic/python/answers/629499-dynamically-displaying-time-using-tkinter-label)

JavaScript

Advertisement

Answer

Well, your code (or at least the portion you posted) seems to be a messy one.

ROS talking,

  • define your subscriber in the initialization of the node (not inside the while loop, that will create multiple subscribers instead!)
  • create a callback to get the messages exchanged under that topic read the message
  • update your label accordingly.

That being said, here’s an example of how the code should look like : (fill in the blanks)

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