How can I create a directly-executable cross-platform GUI app using Python?
Tags: python
Published: 2020-05-22 12:37:14

The <a href="https://python.org">Python</a> programming language works on many platforms including Microsoft Windows, Apple Mac OS X, many Linux distributions other systems.

This article consists of two parts:

* **GUI module** - how to create a desktop interface with Python
* **Python to Executable** - turn a Python program into an executable

The hardest part is learn Python, how to use a GUI module. To create an executable, there are several command line tools.

## GUI module

The first thing you will need is a <a href="https://pythonspot.com/gui/">GUI</a> module. Of course, there are many GUI modules for Python. The most commonly used GUI modules are:

* <a href="https://pythonbasics.org/tkinter/">Tkinter</a> - this module is based on the old Tk GUI toolkit. It is the default GUI library for python and it is free for commercial projects. Tk is rather limited with the number of widgets and has an old design.

![tkinter](https://dev-to-uploads.s3.amazonaws.com/i/q4jgmoor6upfcye3woa4.png)

* <a href="https://pythonpyqt.com/">PyQt</a> - Python bindings for the Qt framework. It's free (gpl) but not for commercial products. Qt comes with many widgets and features and is under continuous development. If you are new to PyQt, I recommend this <a href="https://gumroad.com/l/pysqtsamples">course & book</a>.

![pyqt has many widgets](https://dev-to-uploads.s3.amazonaws.com/i/4432n9qhvonluhyaw6hd.png)

* <a href="https://en.wikibooks.org/wiki/PyGTK_For_GUI_Programming/First_Steps">PyGTK</a>, a wrapper on the GTK toolkit. The gnome (gtk) desktop environment is an option on Linux systems. 

## Python is interpreted

Strictly speaking, you don't have to compile python for Mac/Windows/Linux because it is an <a href="https://pythonprogramminglanguage.com/repl/">interpreted</a> language.

That means that if you have the Python interpreter installed on the platform and the required modules, you can run the program.

Python is installed on every Linux, Mac and Windows OS (I think) by default now. So all you need is have the non-standard modules installed if you use them.

However, your end-users may not be familiar with Python and other installing modules, so you may want to create an executable and an installer.

It is possible to build executables with the python interpreter, which we will discuss in the next section.

## Create executable

After you made your GUI program in Python, you can convert it into a standalone executable. There are several tools that can do this, there is more than one way to do this.

**Cross platform, all platforms**

* <a href="https://www.pyinstaller.org/">PyInstaller</a> - PyInstaller freezes Python apps into stand-alone executables for Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. It supports Python 2.7 and Python 3.3, 3.4, 3.5 and 3.6.

First install it with the <a href="https://pythonbasics.org/how-to-use-pip-and-pypi/">pip</a> package manager:
```
pip install pyinstaller
```
Then run pyinstaller in your programs folder:
```
pyinstaller file.py
```

* <a href="https://build-system.fman.io/">fbs</a> - package Python apps that use PyQt. See <a href="https://pythonbasics.org/compile-pyqt-to-exe/">Python PyQt to executable</a>. fbs is not free for commercial use, but for non-commercial use it's free. It comes with setup program for your end-users.

![fbs setup](https://dev-to-uploads.s3.amazonaws.com/i/re1jzsmg1up46fwb4v7i.png)

**Windows executable**

* <a href="https://py2exe.org/">py2exe</a> - converts your Python program to a windows executable. It's only for building executables on Windows, you can't build a Windows executable from Linux or Mac OS X.

**Linux executable**

* <a href="http://wiki.python.org/moin/Freeze">Freeze</a> - works like py2exe but for the Linux platform

```
python freeze.py hello.py
```

**Mac executable**

* <a href="https://py2app.readthedocs.io/en/latest/">py2app</a> - create Mac OS executables from Python. py2app is similar in purpose and design to py2exe for Windows.