Jul-31-2022, 07:40 PM
I had some free time and was messing tkinter again, i wanted to create a function to open a image so that i could simply call the function to get the image but The Image would not appear in the Frame while calling from the function but if ran in multiple lines of code the image appears just fine. i dont see why the function prevents the image from being placed inside the Frame.
from tkinter import * from PIL import ImageTk,Image root = Tk() root.geometry("400x400") 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() open_image() root.mainloop()