.exe Icon Doesn't Change [py2exe]

让人想犯罪 __ 提交于 2019-12-01 20:08:19

It appears py2exe has a 4-year-old bug on handling icons, but due to its description, I managed to make this workaround:

setup_dict = dict(
    windows = [{'script': "script.py",
                "icon_resources": [(1, "icon.ico")}],
)

setup(**setup_dict)
setup(**setup_dict)

This pretty much builds the project twice. If your project is complex and takes too long to process through py2exe, you can use this to build a dummy py file:

import tempfile
tf = tempfile.NamedTemporaryFile(delete=False)
tf.close()
setup(
    windows = [{
        'script': tf.name,
        "icon_resources":[(1, "icon.ico")]}]
)
os.remove(tf.name)

Just don't forget to set excludes like your project, otherwise you will get your dist folder cluttered with unwanted files.

Please try this

from distutils.core import setup

setup(
    options = {'py2exe': {'bundle_files': 1}},
    zipfile = None,
    windows = [{
            "script":"myproject.py",
            "icon_resources": [(1, "favicon.ico")],
            }],
)

I handled my problem like that;

  1. I used the above code which I post in my question.
  2. Then I installed Resourch Hacker program.
  3. I opened myprogram.exe file with Resourch Hacker program.
  4. Then Action > Replace Icon > I choosed the icon which I want.
  5. And its ok!

For Resourch Hacker tutorial CLICK THIS

I meet the same problem. I have solved it by download a win7 icon from http://www.iconarchive.com/search?q=windows+7&page=5, and the reason should be the icon file that could not work at the very start is not a correct win7 format icon.

this web page https://www.creativefreedom.co.uk/icon-designers-blog/windows-7-icon-sizes/ tells us a topic "Testing your Windows 7 Icon" to check whether a icon is a really win7 icon.

Chud37

I used a different program, came accross pyinstaller from this post and it worked first time.

Installed it:

pip install pyinstaller

Compiled my program:

pyinstaller myprogram.py -i icon.ico

Worked first time! Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!