- 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 update the image of a Tkinter Label widget?
We have used Label widget to group all the widgets in the application. A Label widget takes text and images in the constructor that sets the label with the position in the top-left corner of the window. However, to change or update the image associated with the Label, we can use a callable method where we provide the information of other images.
Example
In the following example, we will create a button to update the Label image.
#Import the required library from tkinter import* from PIL import Image, ImageTk #Create an instance of tkinter frame win= Tk() #Define geometry of the window win.geometry("750x600") win.title("Gallery") #Define a Function to change to Image def change_img(): img2=ImageTk.PhotoImage(Image.open("tutorialspoint.png")) label.configure(image=img2) label.image=img2 #Convert To PhotoImage img1= ImageTk.PhotoImage(Image.open("logo.png")) #Create a Label widget label= Label(win,image= img1) label.pack() #Create a Button to handle the update Image event button= Button(win, text= "Change", font= ('Helvetica 13 bold'), command= change_img) button.pack(pady=15) win.bind("<Return>", change_img) win.mainloop()
Output
Running the example code will display a window with a Label Image and a button that helps to change the label image.
Now, just click the "Change" button to update the Label Image.
- Related Articles
- How to update a Python/tkinter label widget?
- How to update a Button widget in Tkinter?
- How to set the height/width of a Label widget in Tkinter?
- How to Update the label of the Tkinter menubar item?
- Underline Text in Tkinter Label widget
- Update Tkinter Label from variable
- Python Tkinter – How do I change the text size in a label widget?
- How to update an image in a Tkinter Canvas?
- How to center a Tkinter widget?
- How to clear the contents of a Tkinter Text widget?
- How to make a Tkinter widget invisible?
- How to get the width of the Tkinter widget?
- Embedding an Image in a Tkinter Canvas widget using PIL
- How to change the color of a Tkinter label programmatically?
- How to connect a variable to the Tkinter Entry widget?

Advertisements