I'm trying to display an image on a toplevel widget with tkinter.
When I run the code from the python file it all works well, but when I use pyinstaller the image disappears without giving any errors.
PyInstaller command:
pyinstaller --noconfirm --onefile --windowed --icon "C:/Users/Giovanni/Desktop/passgen/key.ico" "C:/Users/Giovanni/Desktop/passgen/spg.py"
Here's the code that I've tried:
Attempt 1
enimg = tkinter.PhotoImage(file="en.png")
enpanel = tk.Label(tutoriallevel, image=enimg)
enpanel.pack()
Attempt 2
from PIL import ImageTk
enimg = ImageTk.PhotoImage(file="en.png")
enpanel = tk.Label(tutoriallevel, image=enimg)
enpanel.pack()
Attempt 3
from PIL import ImageTk, Image
enimg = ImageTk.PhotoImage(Image.open("en.png"))
enpanel = tk.Label(tutoriallevel, image=enimg)
enpanel.pack()
Does anyone knows a solution? Thanks in advance.
EDIT:
I've also tried using the --adddata
argument with PyInstaller but it still doesn't show the image.
New PyInstaller command:
pyinstaller --noconfirm --onefile --windowed --icon "C:/Users/Giovanni/Desktop/passgen/key.ico" --add-data "C:/Users/Giovanni/Desktop/passgen/en.png;." --add-data "C:/Users/Giovanni/Desktop/passgen/ita.png;." "C:/Users/Giovanni/Desktop/passgen/spg.py"