icon1 = wx.Icon("icon.ico", wx.BITMAP_TYPE_ICO)
self.SetIcon(icon1)
This works great if the icon.ico file is a separate file. But it won't
work if I don't have the file.
Is there a way to embed it into the single file exe?
self.SetIcon(Resources.getIcon())
and in our Resources module are the functions generated by the following code:
"""This module contains a simple function to encode any number of
bitmap files to a .py file"""
import os
import glob
from wx.tools import img2py
output = 'bitmaps.py'
# get the list of BMP files
files = glob.glob('*.png') #TODO: chose your extension here
open(output, 'w')
# call img2py on each file
for file in files:
# extract the basename to be used as the image name
name = os.path.splitext(os.path.basename(file))[0]
# encode it
if file == files[0]:
cmd = "-u -i -n %s %s %s" % (name, file, output)
else:
cmd = "-a -u -i -n %s %s %s" % (name, file, output)
img2py.main(cmd.split())
Hope that gets you going,
Hannes
I don't know wxPython, but surely there's no portable way to extract the
icon from the Windows executable. What PyInstaller can do is to embed
the icon into the executable (in Windows, and one day in Mac), but
accessing the icon itself is not something that can be easily done.
You're probably better off adding the icon to your resources, as Hannes
suggested you.
--
Giovanni Bajo