
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
#Import the required library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Create a String Object and set the default value var = StringVar() #Create a text label label = Label(win, textvariable = var, font=('Helvetica 20 italic')) label.pack() #Create an entry widget to change the variable value text = Entry(win, textvariable = var) text.pack() win.mainloop()
Output
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.
Advertisements