Python – How to use py2exe icon_resources in wxPython applications?

How to use py2exe icon_resources in wxPython applications?… here is a solution to the problem.

How to use py2exe icon_resources in wxPython applications?

I

have a wxPython application and I am using py2exe to bundle it into an exe file. I defined an icon in the setup.py file using the following:

setup(
    windows=[
        {
            'script': 'myapp.py',
            'icon_resources': [(1, 'myicon.ico')]
        },
    ],
)

This works, but I would like to be able to access the icon from my wxPython application and use it as the window icon that appears in the upper right corner. Currently I’m using the following load icons from file system:

icon = wx. Icon('myicon.ico', wx. BITMAP_TYPE_ICO, 16, 16)
self. SetIcon(icon)

This works, but requires the icon to be next to the EXE, not the bundle in it.

Solution

I do this in the Frame subclass

if os.path.exists("myWxApplication.exe"):
     self. SetIcon(wx. Icon("myWxApplication.exe",wx. BITMAP_TYPE_ICO))

Related Problems and Solutions