from tkinter import *
from tkinter.filedialog import askopenfile
def uploadImg():
f = askopenfile(filetypes=[('PNG','*.png'),("JPG",'.jpg'),('JPEG','*.jpeg')])
img = PhotoImage(file=f.name)
l.config(image=img,width=img.width(),height=img.height())
btn.place_forget()
# func() # After adding an error line the code works perfectly. (After uncommenting this code shows the image)
root = Tk()
root.config(
padx=50,
pady=50
)
l = Label(master=root,width=100,height=20,borderwidth=1,relief='solid')
l.pack()
btn = Button(master=root,text='Choose A File',command=uploadImg)
btn.place(x=320,y=160)
root.mainloop()
I want my code to show the image on window but it is not.
My code doesn't show the image until I make any error in the uploadImg
function.
Please uncomment the line "func() # After ..."
for this code to work
This is the first time I faces this type of error, To solve this error I have to make any error in my code.
If it's the device problem, Plz tell me in the comment.