Categories
Python Answers

How to make Python tkinter label widget update?

Spread the love

Sometimes, we want to make Python tkinter label widget update.

In this article, we’ll look at how to make Python tkinter label widget update.

How to make Python tkinter label widget update?

To make Python tkinter label widget update, we assign the textvariable argument a StringVar object before we call set to update the label.

For instance, we write

v = StringVar()
Label(master, textvariable=v).pack()

v.set("New Text!")

to create a label with

v = StringVar()
Label(master, textvariable=v).pack()

We set textvariable to a StringVar object to make set update the label.

Then we call set to update the label to display ‘New Text!’.

Conclusion

To make Python tkinter label widget update, we assign the textvariable argument a StringVar object before we call set to update the label.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *