Your browser does not support JavaScript!
Upvotes Anonymous 4 User 0

How to set a Custom Windows Icon with Py2Exe

By default, we see the below taskbar icon when running our CEFPython sample application (built with py2exe):
As shown on the py2exe site, we can add the following line:
"icon_resources": [(1, "myicon.ico")]
to our build_exe.py script. The code is now:
from distutils.core import setup
import py2exe
from cefpython3 import cefpython
import wx
import time
import re
import uuid
import platform
import inspect
import struct
import urllib
setup(
    windows=[{
        'script': 'wxpython.py',
        "icon_resources": [(1, "myicon.ico")]
    }]
)
The icon file I used was created using IcoFX (not free, but very handy) as detailed here. The result is:
To set the icon in the upper-left portion of the application window, you can add the following code (documented here) to the code file (wxPython.py, in our example):
_icon = wx.Icon('app.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(_icon)
Was this helpful?

Comments

Leave a Comment

I agree to the Terms of Service
Design © 2015, Downranked, LLC.,
Original user code contributions under MIT License