I am trying to create a GUI that shows your picture after you upload it. I wrote this code for it. But for some reason, it does not show the image. How can I update the root.mainloop() to show the image?
displaynumber = 0
root = tk.Tk()
f1 = ''
v = tk.IntVar()
def ShowChoice():
print(v.get())
tk.Label(root, text="""Choose method:""", justify = tk.LEFT, padx = 20).pack()
#uploading file
def selecting():
global displaynumber
root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
f1 = root.filename
displaynumber = 2
print (root.filename)
# radio button
tk.Radiobutton(root, text="Select Image from Directory", padx = 20, variable=v, command=selecting, value=1).pack(anchor=tk.W)
# function for displaying image
if displaynumber > 0:
global img
img = ImageTk.PhotoImage(Image.open(f1))
panel = tk.Label(root, image=img)
panel.pack(side="bottom", fill="both")
root.update()
elif displaynumber ==0:
pass
# root mainloop and geometry
root.geometry("1000x500")
root.mainloop()