[Python] Create a Tkinter program distribution file with cx_Freeze

1.First of all

When distributing a GUI program created with Tkinter, I think it is better to pass it as ** Installer ** rather than ** exe executable file **. cx_Freeze had that feature, so I tried it.

This time, the program to be installed is here. (OS: Windows 10, 64bit)

[Python] Show multiple windows in Tkinter

file name:multi_winews_tkinter.py

2. Installation of cx_Freeze

Since I am using Anaconda, I will install it with conda instead of pip.

conda install -c conda-forge cx_freeze

3. Create setup.py file

Create setup.py in the folder where the Python program (* file name: multi_winews_tkinter.py *) is located.

For how to write setup.py, I referred to this page. The sample setup.py for various purposes is easy to use, so please refer to it. (Example: GUI creation with PyQT) https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples

setup.py


import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [
    Executable('multi_windows_tkinter.py', base=base)
]

setup(name='simple_Tkinter',
      version='0.2',
      description='Sample cx_Freeze Tkinter script',
      executables=executables
      )

4. Build the Installer file

In the terminal, execute the following command.

python setup.py bdist_msi

When that happens, an Installer file (msi file) is formed. The capacity of the Installer this time was 11MB.

image.png

5. Run Installer on another PC

Execute the above Installer file on a PC that does not have a Python environment installed. The following screen will be displayed and the installation will start.

image.png

image.png

image.png

As a result of installation, it worked without problems. Finally, if you want to uninstall, you can easily uninstall it with the Windows Control Panel, just like any other Windows Program. It's convenient.

6. Summary

  1. Create a Tkinter program distribution file with cx_Freeze.
  2. Create Installer format instead of Exe format.
  3. Install it on a computer that does not have a Python environment and check that it is working properly.

cx_Freeze Good. It works fast and the size of the generated file is small, so I'm satisfied.

Reference material

  1. [Python] Show multiple windows in Tkinter 2.cx Freeze distutils setup script 3.cx Freeze setup examples

Recommended Posts

[Python] Create a Tkinter program distribution file with cx_Freeze
[Python] Create a file & folder path specification screen with tkinter
Create a frame with transparent background with tkinter [Python]
Create a GUI executable file created with tkinter
Create a Photoshop format file (.psd) with python
Create a directory with python
Create a 2d CAD file ".dxf" with python [ezdxf]
Create a python GUI using tkinter
Create a virtual environment with Python!
Create an Excel file with Python3
Create a binary file in Python
Create a file uploader with Django
Create a Python function decorator with Class
Creating a simple PowerPoint file with Python
[Python] A program that creates stairs with #
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Quickly create an excel file with Python #python
Create a GUI app with Python's Tkinter
Create a large text file with shellscript
Create a VM with a YAML file (KVM)
Read a file in Python with a relative path from the program
Create Excel file with Python + similarity matrix
Create a word frequency counter with Python 3.4
Create a deb file from a python package
[GPS] Create a kml file in Python
I made a configuration file with Python
Create an upgradeable msi file with cx_Freeze
Create a compatibility judgment program with the random module of python.
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
How to read a CSV file with Python 2/3
Create a GIF file using Pillow in Python
Create a LINE BOT with Minette for Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Create a PDF file with a random page size
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
[Python] I made a Youtube Downloader with Tkinter.
Create a matrix with PythonGUI (tkinter combo box)
Steps to create a Twitter bot with python
Create a decision tree from 0 with Python (1. Overview)
Create a new page in confluence with Python
Create a color-specified widget with Python + Qt (PySide)
Create a MIDI file in Python using pretty_midi
Create a Python console application easily with Click
Read line by line from a file with Python
I want to write to a file with Python
Open a file dialog with a python GUI (tkinter.filedialog)
Create a cylinder with open3d + STL file output
Create a Python module
Create a Python environment
Create a native GUI app with Py2app and Tkinter
Try to dynamically create a Checkbutton with Python's Tkinter
Why not create a stylish table easily with Python?
Try embedding Python in a C ++ program with pybind11