简体   繁体   English

如何指定py2app图标?

[英]How to specify py2app icon?

How do I specify the icon file when using py2app?使用py2app时如何指定图标文件?

Just now I create the setup file:刚才我创建了安装文件:

py2applet --make-setup MyApplication.py

and then build the application bundle:然后构建应用程序包:

 python setup.py py2app -A

where is it that I specify the icon file.. getting a little confused.我在哪里指定图标文件..有点困惑。 Thanks for any help.谢谢你的帮助。

according to this link- http://packages.python.org/py2app/options.html , I should add it as an option.根据此链接 - http://packages.python.org/py2app/options.html ,我应该将其添加为选项。

Currently my setup.py file looks like this:目前我的 setup.py 文件如下所示:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['hello.py']
DATA_FILES = ['chalkboard.jpg']
OPTIONS = {'argv_emulation': True,
'iconfile': '/Users/grahamethomson/Documents/College/HND/oop/game/personal       developoment/G/icon.icns'}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

In your setup.py, add iconfile在 setup.py 中,添加 iconfile

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['main.py']
DATA_FILES = []
OPTIONS = {
    'iconfile':'icon.icns',
    'plist': {'CFBundleShortVersionString':'0.1.0',}
}

setup(
    app=APP,
    name='MacApp',
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Answering my own question.回答我自己的问题。

To add an icon file simply add the iconfile option when creating setup.py:要添加图标文件,只需在创建 setup.py 时添加 iconfile 选项:

py2applet --make-setup foo.py --iconfile images/icon.icns

Note: You must not leave the icon.icns under the same folder as your main script foo.py .注意:您不得将icon.icns与主脚本foo.py同一文件夹下。 It must be placed under a subfolder like images/ , otherwise you'd end up with DATA_FILE=['--iconfile'] in your setup.py , which would fail because that's not a data file.它必须放在像images/这样的子文件夹下,否则你最终会在setup.py得到DATA_FILE=['--iconfile'] ,这会失败,因为那不是数据文件。

These solutions didn't work for me on python3.这些解决方案在 python3 上对我不起作用。 The --iconfile switch was throwing errors about not finding the file. --iconfile 开关抛出关于找不到文件的错误。 In fact the switch is not even needed.事实上,甚至不需要开关。 This worked for me.这对我有用。

py2applet --make-setup MyApplication.py myicon.icns
python3 setup.py py2app

Just put the icon in the same folder as the source code and this does what you want.只需将图标放在与源代码相同的文件夹中,即可完成您想要的操作。 Found in py2applet help .py2applet 帮助中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM