How to distribute a Python tkinter file as an “.exe file”

How to distribute a Python tkinter file as an “.exe file”

I’ve had to distribute an application using Python’s tkinter as an execution file, so I’ll make a note of it.

If you want to make an application in Python and give it to someone to use, I think it would be unfriendly to give them the Python file directly.

In such a case, it would be better to give it to the user as an executable file to make it easier to use.

This time, we will use a library called pyinstaller.

Aiming executable and conclusion

The target executable is as follows.

  • The logo of the executable will be displayed on the icon.
  • Display your own logo instead of the tkinter logo on the top-left icon at startup.
  • You can use it like a normal application.

 

In conclusion, if you type the following command, you can run the software normally with the logo in the application without starting a black Window.。

pyinstaller --onefile --noconsole --icon=img/icon.ico YOUR_FILE.py

Explanation of each option of the command

Make it one executable file:–onefile

I thought it would be easier to combine them into one executable file instead of a format that requires multiple library files at the time of distribution, so I will add this option.

Make one startup window:–noconsole

If nothing is specified in pyinstaller, a black screen window will also be displayed.

This black screen displays the results of standard output such as print statements, which is useful for debugging, but not necessary for distribution.

This black screen is useful for debugging, but is not necessary for distribution, so it should not be displayed.

Add a logo to the application:–icon

Store the icon image in the specified directory and specify it there.

 

Changing the tkinter logo in the upper left corner of the screen

Write it directly in the source, as shown in this link. Is there a better way?
Note: The link is in Japanese, please use Google Translate to see it.

I did this because I wanted to have only one executable file at the time of distribution.

Summary

I have explained how to make a python application into an executable file.

I’ve heard rumors that using pyinstaller can increase data size and slow startup.

In my case, it was only about 5MB, and it took only 1-2 seconds to start up, so I didn’t feel particularly dissatisfied.

What you can’t (or won’t) do with this method

If you create an executable file by yourself, even if it is not pyinstaller, you will get a “pc protected by windows” message when you run it.

To avoid this, Windows needs to be signed by the provider, but it is expensive.

You can also create your own certificate, like a server on the Internet, but you will have to ask your users to download the certificate.

I don’t think this is very beneficial.

So, I decided to skip the certificate this time.

Translated with www.DeepL.com/Translator (free version)