
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
Change Tkinter Label Text Dynamically Using Label Configure
The Label widget in tkinter is generally used to display text as well as image. Text can be added in a Label widget by using the constructor Label(root, text= "this is my text"). Once the Label widget is defined, you can pack the Label widget using any geometry manager.
If you want to configure the Label widget, you can use the configure() property. The configure() method allows you to edit the text as well other properties of the Label widget dynamically.
Example
Let us take an example to understand how we can dynamically change the tkinter label text using the configure() method. In this example, we will create a Label text widget and a button to update the text of the label widget.
# Import the required library from tkinter import * # Create an instance of tkinter frame or widget win = Tk() win.geometry("700x350") def update_text(): # Configuring the text in Label widget label.configure(text="This is updated Label text") # Create a label widget label=Label(win, text="This is New Label text", font=('Helvetica 14 bold')) label.pack(pady= 30) # Create a button to update the text of label widget button=Button(win, text= "Update", command=update_text) button.pack() win.mainloop()
Output
Running the above code will display a window with a label widget containing some text and a button.
When you click the button, it will update the text.