Python 3 Tkinter Update Image of Label or PhotoImage Widget on Button Click Event GUI Desktop App Full Project For Beginners

 

 

 

main.py

 

#Import the required library
from tkinter import*
from PIL import Image,ImageTk
from tkinter import ttk
#Create an instance of tkinter frame
win= Tk()
#Define geometry of the window
win.geometry("750x450")
#Define a Function to update to Image
def update_img():
   img2=ImageTk.PhotoImage(Image.open("Frame0.jpg"))
   label.configure(image=img2)
   label.image=img2
#Load the Image
img1= ImageTk.PhotoImage(Image.open("Frame1.jpg"))
#Create a Label widget
label= Label(win,image= img1)
label.pack()
#Create a Button to handle the update Image event
button= ttk.Button(win, text= "Update", command= update_img)
button.pack(pady=15)
win.bind("<Return>", update_img)
win.mainloop()

Leave a Reply