Update Tkinter Label from variable

To display the text and images in an application window, we generally use the Tkinter Label widget. In this example, we will update the Label information by defining a variable. Whenever the information stored in the variable changes, it will update the Label as well. We can change the Label information while defining the textvariable property in the Label widget.


#Import the required library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
#Create a String Object and set the default value
var = StringVar()
#Create a text label
label = Label(win, textvariable = var, font=('Helvetica 20 italic'))
#Create an entry widget to change the variable value
text = Entry(win, textvariable = var)


Running the above code will display a window with an entry widget and a Label. The Label gets updated whenever we enter some text in the Text Field.