TheKraken
TheKraken

Reputation: 11

Pyinstaller EXE integrated with PNG background and ICO as icon

Please I need to create a distributable EXE file as only ONE file from Python 3.7 code, that includes integrated a PNG image as a background and ICO image as an Icon using pyinstaller. So far, all the EXE files that I have created need the PNG and ICO files in order to be distributed and run, losing the main goal of the EXE as only ONE file distributed.

I did the setting of full path for files PNG and ICO in the code but the EXE only run in my pc and the files must be located in the specified path.

Even using AUTO-PY-TO-EXE the result is the same.

I need that EXE file has integrated the PNG and ICON files.

Please any suggestion and/or reference to any similar post solved.

For any test just use any PNG and ICO file including full path location.

from tkinter import *
root=Tk()

#set windows size
root.resizable(width=False, height=False)
root.geometry("925x722")

#set title
root.title("SOFT1)")

#frame 1
f1=Frame(root, width=345,height=475,bg="light 
grey",highlightbackground="black",highlightthickness=4)
f1.place(x=20,y=235)

#set a image as BG
Logo=PhotoImage(file="PNG_File.png")
lab6=Label(root, image=Logo)
lab6.place(x=0, y=0)

#set a image as ICON
root.iconbitmap("ICO_File.ico")

mainloop()

Upvotes: 1

Views: 696

Answers (2)

Tom
Tom

Reputation: 21

I hope until now you found your solution, but I saw in another post that explained the same concept. I copied this function below and when i needed to create the image files in my app i used this function and inside the file name:

def resource_path(relative_path):
try:
    base_path = sys._MEIPASS
except Exception:
    base_path = os.path.abspath(".")

return os.path.join(base_path, relative_path)

I tried afterward to run my .py file with auto-py-to-exe and that solved the problem for me.

Upvotes: 1

Grace
Grace

Reputation: 335

From a brief look at what you're doing, you can't do that. Have you considered distributing your program as a .zip instead?

You can't do what you're trying to do because that load function is taking a file path - specifically a file path to the directory the script is run in, and searching for images in that directory. Without the images being there, it will fail on loading them. It's that simple.

Upvotes: 0

Related Questions