Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Add An Icon Of My Own To A Python Program

Tags:

python

I am developing a game in Python and was wondering how to give it its own icon. I am using a windows computer and have no extra things installed with Python. Oh also I am using version 3.3 Is this even possible.

P.S I have found other things on Stack Overflow but they are using different Operating Systems like Ubuntu and Macintosh

like image 387
Ethan Bacon Avatar asked May 28 '13 00:05

Ethan Bacon


People also ask

How do I change the icon of a Python exe?

ico file back. To change the icon that the .exe has, you can pass the --icon=icon. ico to the pyi-makespec command or modify the . spec file yourself by altering the exe object to add the argument icon='icon.

How do I use icons in PyInstaller?

Use the --icon argument to specify a custom icon for the application. It will be copied into the Resources folder. (If you do not specify an icon file, PyInstaller supplies a file icon-windowed. icns with the PyInstaller logo.)

How do I get the Python script icon on my desktop?

Right-click the script and select create a shortcut. Right-click the new shortcut and select properties. Under the shortcut tab, note the target option.

How do I set up Python apps?

If you wish to create a new Python application, you must specify the Python version, fill in the Application root, and the Application URL. Then click Create. Optionally, you can also set up Application startup file, Application Entry point and Passenger log file.


4 Answers

There are two steps: first build the Python executable. For this you will need something like py2exe, "which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."

Then once you have your executable, to give it an icon, you can use the answer to this question: Add icon to existing EXE file from the command line for that finishing touch.

like image 111
Dmitri Avatar answered Nov 08 '22 18:11

Dmitri


You can't add a custom icon to a plain Python script, but if you convert it to a Windows executable using py2exe, you can specify icon resources to use for it. There's a how-to on their wiki.

like image 22
Cairnarvon Avatar answered Nov 08 '22 18:11

Cairnarvon


Update (2021-11-3):

Py2Exe new versions are now available so @dmitris's solution will now work although PyInstaller is another option. However the Python 3.5 series of Py2Exe ended on September 30, 2020.


Original Answer:

@dmitri's solution works but Py2Exe stopped development at python 3.4 and will not work with newer versions PyInstaller would also do this.

pip install pyinstaller
pyinstaller --onefile --windowed --icon=youricon.ico yourprogram.py

Python version 3.7.3.

like image 43
recurseuntilfor Avatar answered Nov 08 '22 19:11

recurseuntilfor


If you are trying to change the icon of the shortcut for your program,

  • then you need to get to the file where ever it is right-click it and go to create a shortcut

  • then drag that shortcut to your desktop

  • then right-click that shortcut and click properties

  • then click on "Change Icon"

  • then go to where your desire .ico image is saved and set that as the icon

if you do this and you open your program in the corner will be the .ico you selected and on your desktop, it will show the icon instead of the python image.

that is how you change the shortcut icon but there is no way to change the actual window icon in the corner unless you're using something like Tk or Pygame.

like image 43
Serial Avatar answered Nov 08 '22 18:11

Serial