Reading icon in a .exe with tkinter's iconbitmap

Viewed 1868

My app is built into a single .exe file with py2exe. Instead of this code (which works when I have a .ico file) :

root.iconbitmap(default='test.ico')

I would like to use

root.iconbitmap(default='test.exe')

because since I have a single .exe file, I don't have a .ico file anymore...

It doesn't work :

_tkinter.TclError: bitmap "D:\temp\test.exe" not defined

This file exists, but it seems that iconbitmap cannot read an icon from a .exe with embedded icons...

How to read icons embedded in a .exe file with tkinter's iconbitmap ?

2 Answers

Since the icon has to be a .ico file, you could try to convert your image into a .ico file, for example here is some code I had to use for a Tkinter program and you can use the second line to convert your image into a .ico file to then use it:

ico = Image.open('Image_dossier/Cover.png')
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(False, photo)
Related