Aug-02-2022, 09:13 PM
Return photo to keep a reference to it, or append to a list, which is mutable. Both are illustrated below.
from tkinter import * from PIL import ImageTk,Image root = Tk() root.geometry("400x400") photo_list=[] def open_image(): frame = Frame(root,width=200,height=200,bd=5,bg='white') photo = ImageTk.PhotoImage(Image.open('image.jpg')) photo_label = Label(image=photo) photo_label.pack() photo_list.append(photo) return photo photo=open_image() root.mainloop()