I have tried this slighty altered code from YouTube and it is not working. The program is supposed to pack a photo on launch, and then pack it into the screen. The functions are supposed to do the same thing, but with selected file. Every button works without any issues, but the image is not being put onto the screen. There is space made for the image but it doesnt render.
from tkinter import *
from tkinter import filedialog
from PIL import ImageTk,Image
root = Tk()
root.title("File Dialog")
def askforfile():
imgdir = filedialog.askopenfilename(initialdir="/pygiu/img",title="Select a nice photo", filetypes=(("PNG files", "*.png"), ("JPEG files", "*.jpg"), ("All files", "*")))
showbutt = Button(root, text="Pokaż zdjęcie", command=showfile(imgdir))
def showfile(dir):
img = ImageTk.PhotoImage(Image.open(dir))
img_label = Label(image=img)
img_label.pack()
butt = Button(root, text="Wybierz zdjęcie", command=askforfile).pack()
img = ImageTk.PhotoImage(Image.open("/home/<username>/Dokumenty/Projects/pygui/ikona.png"))
img_label = Label(image=img)
img_label.pack()
root.mainloop()
App before selecting the photo
App after selecting the photo