In the next code I am tryng to display an image in my frame:
from tkinter import PhotoImage
import tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
root.title("My window")
root.geometry('500x400')
frame = tk.Frame(root)
frame.pack(fill='both', expand=1)
def insertImage():
picture = ImageTk.PhotoImage(Image.open('pic.jpeg'))
lbl_picture_img = tk.Label(frame, image=picture)
lbl_picture_img.pack()
# picture = ImageTk.PhotoImage(Image.open('pic.jpeg'))
# lbl_picture_img = tk.Label(frame, image=picture)
# lbl_picture_img.pack()
insertImage()
root.mainloop()
But when I run insertImage()
I just get an empty window.
But if I uncomment those 3 lines and run my code, I can see my window with the picture:
My goal is to display the picture by running a method, that is why I am not satisfied by displaying it with the comment lines.I hope you can help me, thanks.