5

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 ?

Basj
  • 41,386
  • 99
  • 383
  • 673

2 Answers2

0

You can try to generate the icon on the fly just before the main loop of your application as in the third answer of this question. (Still you need to figure out how to write your icon to the string, but maybe that's a good question too!)

Community
  • 1
  • 1
Alvaro Fuentes
  • 16,937
  • 4
  • 56
  • 68
  • Yes I don't know either how to do this. A more direct option would be to extract and use the icon from the .exe, but how ? – Basj Dec 20 '13 at 21:38
0

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)
Dhamo
  • 1,171
  • 3
  • 19
  • 41