- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change Tkinter label text on button press?
Most often, Tkinter Label widgets are used in the application to display the text or images. We can configure the label widget such as its text property, color, background or foreground color using the config(**options) method.
If you need to modify or change the label widget dynamically, then you can use a button and a function to change the text of the label widget.
Example
# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the tkinter window win.geometry("700x350") # Define a function update the label text def on_click(): label["text"] = "Python" b["state"] = "disabled" # Create a label widget label = Label(win, text="Click the Button to update this Text", font=('Calibri 15 bold')) label.pack(pady=20) # Create a button to update the label widget b = Button(win, text="Update Label", command=on_click) b.pack(pady=20) win.mainloop()
Output
When you run the above code, it will show a label text and a button in the window.
When you click the button, it will just update the label text.
Advertisements