I started coding recently and decided to start with python. I want to make a program that loads an image from a file open dialog, and then shows that image in my root(). That works, but when I put the loading part in a function it shows the space where the image should be, but no image. My code is:
from tkinter import *
from tkinter import filedialog
from shutil import copyfile
from PIL import ImageTk, Image
import numpy as np
import cv2
root = Tk()
#root.withdraw()
topFrame = Frame(root)
topFrame.pack()
bottomFrame = Frame(root)
bottomFrame.pack(side=BOTTOM)
def odaberiSliku():
root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
img = (root.filename)
copyfile(img,"test.jpg")
#root.deiconify()
photo = ImageTk.PhotoImage(Image.open("test.jpg"))
label = Label(bottomFrame, image=photo)
label.pack()
return
button_load = Button(topFrame, text="Odaberi sliku", command=odaberiSliku)
button_load.pack()
root.mainloop()
I get a window like this:
Thank you.