Python tk update label
Active Oldest Votes. Try this just after setting the status bar text: tk. Improve this answer. Maddy Maddy 61 1 1 bronze badge. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.
Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 0. Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert.
Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Python. When you do that, any update to the variable will update the label. However, you end up having to make a function call to update the variable, so you don't really gain anything over making a function call to update the label directly.
Another option is to use two labels -- one for the static text and one for the variable. Put them side-by side with no border so the user won't notice. Then, when you update the variable you'll get the desired effect.
However, you're still having to make a function call to set the variable so you don't really gain much. Yet another option is to use two instances of StringVar -- one for the label, and another for the name.
You can put a trace on the name variable so that when it changes, you automatically update the other variable with the static string and the value of the name variable, and that will cause the label to be automatically updated.
Again, however, you're having to make a function call to put everything in motion. So, as you can see, there are options, but they all add complexity to your code with no real gain over simply updating the label directly.
The only time these other methods gain you an advantage is when the value needs to appear in more than one widget at once. In that case you can associate the variable with two or more widgets, and a single function call will update all associated widgets. You may use. You may also want to know about a more advanced tools for Tkinter variables. There are also more powerful tools associated with Tkinter variables -- called trace -er s -- which set the Tkinter system to "watch" any change to a "traced" variable and this can associate further automated responsive activities, automatically launched upon a traced-event-type.
This instrumentation helps you create your GUI toolbox strategies very powerful for an efficient, event-driven, fully self-reflecting layered [Model-Visual-Controller], supervised under the hood of the Tkinter. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Asked 7 years, 3 months ago. Active 1 year ago. Viewed 29k times.
0コメント