2

I'm having trouble with my pyinstaller executable, when I launch it I get this error:

enter image description here

The problem is due to the exe not being able to find an image file 'icon.ico' because pyinstaller didn't package the file inside the executable file. What I'm asking is how I would package the icon inside the EXE file and what the directory for that icon file would be after it has been packaged. The image file is being used as an icon for a Tkinter GUI.

This is the code for the Tkinter app:

app = Tk()
app.title('MagnetMagnet - RARBG Scraper')
app.iconbitmap(r'icon.ico')
app.geometry('500x225')

app.mainloop()
martineau
  • 119,623
  • 25
  • 170
  • 301
eliasbenb
  • 169
  • 13

2 Answers2

2

An easy way is save the Bytes of the Image,and when open it,Save the picture in your PC,and use app.iconbitmap(r'icon.ico').

Firstly,use open to get the Image Bytes:

with open('icon.ico','rb') as f:
    ImageBytes = f.read()
print(ImageBytes)
# b'xxxxxxxxxxxxxxxxxx'

Then your all code should be:

ImageBytes = b'xxxxxxxxxxxxxxxxxx'
with open('icon.ico','wb') as f:
    f.write(ImageBytes)
app = Tk()
app.title('MagnetMagnet - RARBG Scraper')
app.iconbitmap(r'icon.ico')
app.geometry('500x225')
app.mainloop()

When you open this exe file,it will generate a new ico Image,you can delete it.And it will generate a new one again next time when you open it.

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
  • 1
    This is a really easy method! Thanks! I was scratching my head trying to understand whatever this man did: https://stackoverflow.com/questions/31836104/pyinstaller-and-onefile-how-to-include-an-image-in-the-exe-file But you swooped in and saved me a lot of time Thank you kind stranger – eliasbenb Mar 14 '20 at 15:44
1

I think you don't have to give the icon in the python file. instead type pyinstaller -i iconfile pythonfile in your terminal(Windows)

Sven
  • 1,014
  • 1
  • 11
  • 27