0

I'm unable to update the canvas image using itemconfig() method by button click. when i click the button the first image disappears but another image is not showing. Please check my code and help me

from tkinter import Tk, Button, Entry, Canvas, PhotoImage
from PIL import ImageTk, Image

# _______________________________ Functions _____________________________________

def select_func():
    picture = Image.open("img.png")
    picture.thumbnail((500, 350))
    img = ImageTk.PhotoImage(picture)
    canv.itemconfig(thumb_pic, image=img)


#______________________________________ GUI _____________________________________

window = Tk()

window.config(padx=25, pady=50, bg="#C2DED1")
window.minsize(width=550, height=600)
window.maxsize(width=650, height=700)
window.title("Hemo Color Extraction program")


#_____________________________ Button ___________________________

update = Button(text="Select", command=select_func, padx=20)
update.grid(column=0, row=0, padx=50)


# __________________________ Create Image Thumbnail _____________________________

canv = Canvas(bg="#C2DED1", highlightthickness=0)
canv.grid(column=0, row=1, columnspan=3, pady=10)

picture = Image.open("sample.jpg")
picture.thumbnail((500, 350))
img = ImageTk.PhotoImage(picture)

thumb_pic = canv.create_image(50, 50, image=img, anchor='nw')



window.mainloop()
martineau
  • 112,593
  • 23
  • 157
  • 280

0 Answers0