Python GUI examples (Tkinter Tutorial)

Tkinter introduction
Python Binding function in Tkinter
How to Create a GUI Restaurant Management Systems in Python
python frontend backend tkinter



Python GUI examples
In this tutorial, we will learn how to develop graphical user interfaces by writing some Python GUI examples using Tkinter package.
Tkinter package is shipped with Python as a standard package, so we don’t need to install anything to use it.
Tkinter package is a very powerful package. If you already have installed Python, you may use IDLE which is the integrated IDE that is shipped with Python, this IDE is written using Tkinter. Sounds Cool!!
We will use Python 3.6, so if you are using Python 2.x, it’s strongly recommended to switch to Python 3.x unless you know the language changes so you can adjust the code to run without errors.
I assume that you have a little background about Python basics to help you understand what we are doing.
We will start by creating a window then we will learn how to add widgets such as buttons, combo boxes, etc, then we will play with their properties, so let’s get started.

Table of Contents
1 Create your first GUI application
2 Create a label widget
2.1 Set label font size
2.2 Setting window size
3 Adding a button widget
3.1 Change button foreground and background colors
3.2 Handle button click event
4 Get input using Entry class (Tkinter textbox)
4.1 Set focus to entry widget
4.2 Disable entry widget
5 Add a combobox widget
6 Add a Checkbutton widget (Tkinter checkbox)
6.1 Set check state of a Checkbutton
7 Add radio buttons widgets
7.1 Get radio button value (selected radio button)
8 Add a ScrolledText widget (Tkinter textarea)
8.1 Set scrolledtext content
8.2 Delete/Clear scrolledtext content
9 Create a MessageBox
9.1 Show warning and error messages
9.2 Show askquestion dialogs
10 Add a SpinBox (numbers widget)
10.1 Set default value for Spinbox
11 Add a Progressbar widget
11.1 Change Progressbar color
12 Add a filedialog (file & directory chooser)
12.1 Specify file types (filter file extensions)
13 Add a Menu bar
14 Add a Notebook widget (tab control)
14.1 Add widgets to Notebooks
15 Add spacing for widgets (padding)

Create your first GUI application

First, we will import Tkinter package and create a window and set its title: ======== from tkinter import * window = Tk() window.title("Welcome to LikeGeeks app") window.mainloop() The result will be like this: Awesome!! Our application just works. The last line which calls mainloop function, this function calls the endless loop of the window, so the window will wait for any user interaction till we close it. If you forget to call the mainloop function, nothing will appear to the user.

Create a label widget

To add a label to our previous example, we will create a label using the label class like this: lbl = Label(window, text="Hello") Then we will set its position on the form using the grid function and give it the location like this: lbl.grid(column=0, row=0) So the complete code will be like this: ======== from tkinter import * window = Tk() window.title("Welcome to LikeGeeks app") lbl = Label(window, text="Hello") lbl.grid(column=0, row=0) window.mainloop() ======== from tkinter import * window = Tk() lbl.grid(column=0, row=0) window.mainloop() And this is the result: Without calling the grid function for the label, it won’t show up.

Set label font size

You can set the label font so you can make it bigger and maybe bold. You can also change the font style. To do so, you can pass the font parameter like this: lbl = Label(window, text="Hello", font=("Arial Bold", 50)) Note that the font parameter can be passed to any widget to change its font not labels only. Great, but the window is so small, we can even see the title, what about setting the window size?

Setting window size

We can set the default window size using geometry function like this: window.geometry('350x200') The above line sets the window width to 350 pixels and the height to 200 pixels. Let’s try adding more GUI widgets like buttons and see how to handle button click event.  

Adding a button widget

Let’s start by adding the button to the window, the button is created and added to the window the same as the label: btn.grid(column=1, row=0) So our window will be like this: ======== from tkinter import * window = Tk() window.title("Welcome to LikeGeeks app") window.geometry('350x200') lbl = Label(window, text="Hello") lbl.grid(column=0, row=0) btn = Button(window, text="Click Me") btn.grid(column=1, row=0) window.mainloop() ======== from tkinter import * window = Tk() window.geometry('350x200') lbl.grid(column=0, row=0) btn.grid(column=1, row=0) window.mainloop() The result looks like this: Note that we place the button on the second column of the window which is 1. If you forget and place the button on the same column which is 0, it will show the button only, since the button will be on the top of the label.

Change button foreground and background colors

You can change foreground for a button or any other widget using fg property. Also, you can change the background color for any widget using bg property. btn = Button(window, text="Click Me", bg="orange", fg="red") Now, if you tried to click on the button, nothing happens because the click event of the button isn’t written yet.

Handle button click event

First, we will write the function that we need to execute when the button is clicked: def clicked(): lbl.configure(text="Button was clicked !!") def clicked(): Then we will wire it with the button by specifying the function like this: btn = Button(window, text=“Click Me”, command=clicked) Note that, we typed clicked only not clicked() with parentheses. Now the full code will be like this: ======== from tkinter import * window = Tk() window.title("Welcome to LikeGeeks app") window.geometry('350x200') lbl = Label(window, text="Hello") lbl.grid(column=0, row=0) def clicked(): lbl.configure(text="Button was clicked !!") btn = Button(window, text="Click Me", command=clicked) btn.grid(column=1, row=0) window.mainloop() ======== from tkinter import * window = Tk() window.geometry('350x200') lbl.grid(column=0, row=0) def clicked(): btn.grid(column=1, row=0) window.mainloop() And when we click the button, the result as expected: Cool!!  

What is PyQt5?

This PyQt5 tutorial shows how to use Python 3 and Qt to create a GUI. It even covers creating an installer for your app. PyQt is a library that lets you use the Qt GUI framework from Python. Qt itself is written in C++. By using it from Python, you can build applications much more quickly while not sacrificing much of the speed of C++. PyQt5 refers to the most recent version 5 of Qt. You may still find the occasional mention of (Py)Qt4 on the web, but it is old and no longer supported. An interesting new competitor to PyQt is Qt for Python. Its API is virtually identical. Unlike PyQt, it is licensed under the LGPL and can thus be used for free in commercial projects. It's backed by the Qt company, and thus likely the future. We use PyQt here because it is more mature. Since the APIs are so similar, you can easily switch your apps to Qt for Python later.

Install PyQt

The best way to manage dependencies in Python is via a virtual environment. A virtual environment is simply a local directory that contains the libraries for a specific project. This is unlike a system-wide installation of those libraries, which would affect all of your other projects as well. To create a virtual environment in the current directory, execute the following command:

python3 -m venv venv

This creates the venv/ folder. To activate the virtual environment on Windows, run:

call venv/scripts/activate.bat

On Mac and Linux, use:

source venv/bin/activate

You can see that the virtual environment is active by the (venv) prefix in your shell:

Creating and activating a Python virtual environment

To now install PyQt, issue the following command:

pip install PyQt5==5.9.2

The reason why we're using version 5.9.2 is that not all (Py)Qt releases are equally stable. This version is guaranteed to work. Besides this subtlety – Congratulations! You've successfully set up PyQt5.

Create a GUI

Time to write our very first GUI app! With the virtual environment still active, start Python. We will execute the following commands:

Python code of a Hello World PyQt app on Ubuntu Linux

First, we tell Python to load PyQt via the import statement:

from PyQt5.QtWidgets import QApplication, QLabel

Next, we create a QApplication with the command:

app = QApplication([])

This is a requirement of Qt: Every GUI app must have exactly one instance of QApplication. Many parts of Qt don't work until you have executed the above line. You will therefore need it in virtually every (Py)Qt app you write. The brackets [] in the above line represent the command line arguments passed to the application. Because our app doesn't use any parameters, we leave the brackets empty. Now, to actually see something, we create a simple label:

label = QLabel('Hello World!')

Then, we tell Qt to show the label on the screen:

label.show()

Depending on your operating system, this already opens a tiny little window:

Screenshot of Hello World PyQt application

The last step is to hand control over to Qt and ask it to "run the application until the user closes it". This is done via the command:

app.exec_()

If all this worked as expected then well done! You've just built your first GUI app with Python and Qt.

Widgets

Everything you see in a (Py)Qt app is a widget: Buttons, labels, windows, dialogs, progress bars etc. Like HTML elements, widgets are often nested. For example, a window can contain a button, which in turn contains a label. The following screenshot shows the most common Qt widgets:

Screenshot of the most common PyQt widgets

Top-to-bottom, left-to-right, they are:

You can download the code for the app shown in the screenshot here, if you are interested.

Layouts

Like the example above, your GUI will most likely consist of multiple widgets. In this case, you need to tell Qt how to position them. For instance, you can use QVBoxLayout to stack widgets vertically:

QVBoxLayout example

The code for this screenshot is:

from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
app = QApplication([])
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(QPushButton('Top'))
layout.addWidget(QPushButton('Bottom'))
window.setLayout(layout)
window.show()
app.exec_()

As before, we instantiate a QApplication. Then, we create a window. We use the most basic type QWidget for it because it merely acts as a container and we don't want it to have any special behavior. Next, we create the layout and add two QPushButtons to it. Finally, we tell the window to use this layout (and thus its contents). As in our first application, we end with calls to .show() and app.exec_(). There are of course many other kinds of layouts (eg. QHBoxLayout to lay out items in a row). See Qt's documentation for an overview.

Custom styles

One of Qt's strengths is its support for custom styles. There are many mechanisms that let you customize the look and feel of your application. This section outlines a few.

Built-in styles

The coarsest way to change the appearance of your application is to set the global Style. Recall the widgets screenshot above:

Screenshot of common Qt widgets using the Fusion style

This uses a style called Fusion. If you use the Windows style instead, then it looks as follows:

Screenshot of common Qt widgets using the Windows style

To apply a style, use app.setStyle(...):

from PyQt5.QtWidgets import *
app = QApplication([])
app.setStyle('Fusion')
...

The available styles depend on your platform but are usually 'Fusion', 'Windows', 'WindowsVista' (Windows only) and 'Macintosh' (Mac only).

Custom colors

If you like a style, but want to change its colors (eg. to a dark theme), then you can use QPalette and app.setPalette(...). For example:

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QApplication, QPushButton

app = QApplication([])
app.setStyle('Fusion')
palette = QPalette()
palette.setColor(QPalette.ButtonText, Qt.red)
app.setPalette(palette)
button = QPushButton('Hello World')
button.show()
app.exec_()

This changes the text color in buttons to red:

Screenshot of a QPushButton with red text in the Fusion style

For a dark theme of the Fusion style, see here.

Style sheets

In addition to the above, you can change the appearance of your application via style sheets. This is Qt's analogue of CSS. We can use this for example to add some spacing:

from PyQt5.QtWidgets import QApplication, QPushButton
app = QApplication([])
app.setStyleSheet("QPushButton { margin: 10ex; }")
button = QPushButton('Hello World')
button.show()
app.exec_()
Qt window with a button surrounded by extra space

For more information about style sheets, please see Qt's documentation.

Signals / slots

Qt uses a mechanism called signals to let you react to events such as the user clicking a button. The following example illustrates this. It contains a button that, when clicked, shows a message box:

from PyQt5.QtWidgets import *
app = QApplication([])
button = QPushButton('Click')
def on_button_clicked():
    alert = QMessageBox()
    alert.setText('You clicked the button!')
    alert.exec_()

button.clicked.connect(on_button_clicked)
button.show()
app.exec_()
PyQt QMessageBox saying that a button was clicked

The interesting line is highlighted above: button.clicked is a signal, .connect(...) lets us install a so-called slot on it. This is simply a function that gets called when the signal occurs. In the above example, our slot shows a message box. The term slot is important when using Qt from C++, because slots must be declared in a special way in C++. In Python however, any function can be a slot – we saw this above. For this reason, the distinction between slots and "normal" functions has little relevance for us. Signals are ubiquitous in Qt. And of course, you can also define your own. This however is beyond the scope of this tutorial.

Compile your app

You now have the basic knowledge for creating a GUI that responds to user input. Say you've written an app. It runs on your computer. How do you give it to other people, so they can run it as well? You could ask the users of your app to install Python and PyQt like we did above, then give them your source code. But that is very tedious (and usually impractical). What we want instead is a standalone version of your app. That is, a binary executable that other people can run on their systems without having to install anything. In the Python world, the process of turning source code into a self-contained executable is called freezing. Although there are many libraries that address this issue – such as PyInstaller, py2exe, cx_Freeze, bbfreze, py2app, ... – freezing PyQt apps has traditionally been a surprisingly hard problem. We will use a new library called fbs that lets you create standalone executables for PyQt apps. To install it, enter the command:

pip install fbs

Then, execute the following:

fbs startproject

This prompts you for a few values:

Commands for starting a new project with fbs

When you type in the suggested run command, an empty window should open:

An empty window showing 'Hello World!' in its title

This is a PyQt5 app just like the ones we have seen before. Its source code is in src/main/python/main.py in your current directory. But here's the cool part: We can use fbs to turn it into a standalone executable!

fbs freeze

This places a self-contained binary in the target/MyApp/ folder of your current directory. You can send it to your friends (with the same OS as yours) and they will be able to run your app! (Please note that fbs currently targets Python 3.5 or 3.6. If you have a different version and the above does not work, please install Python 3.6 and try again. On macOS, you can also install Python 3.5 with Homebrew.)

Bonus: Create an installer

fbs also lets you create an installer for your app via the command fbs installer:

(If you are on Windows, you first need to install NSIS and place it on your PATH.)

For more information on how you can use fbs for your existing application, please see this article. Or fbs's tutorial.

Summary

If you have made it this far, then big congratulations. Hopefully, you now have a good idea of how PyQt (and its various parts) can be used to write a desktop application with Python. We also saw how fbs lets you create standalone executables and installers.




PyQt5 tutorial – Python GUI programming examples

In a previous tutorial, we talked about the Tkinter module and we saw how to build GUI apps using it. In this tutorial, we will continue building graphical interfaces in Python and this time we will use PyQt5.

PyQt5 is one of the most used modules in building GUI apps in Python and that’s due to its simplicity as you will see.

Another great feature that encourages developers to use PyQt5 is the PyQt5 designer which makes it so easy to develop complex GUI apps in a short time. You just drag your widgets to build your form.

In this PyQt5 tutorial, I will use Python 3.6 on Windows 10 and I assume that you know some Python basics.

Sound great! So let’s get started and install PyQt5 at first then we will see how to develop GUI apps with examples.

Table of Contents

 

Install PyQt5

PyQt5 has two versions, the commercial version and the free GPL version that we will use in this tutorial.

To install PyQt5, you have two ways:

Using pip

To install PyQt5 using pip, run the following command:

To ensure the successful installation, run the following Python code:

import PyQt5

If no errors appeared, that means you have successfully installed PyQt5, but if you got errors, you may be using an unsupported version of Python.

Using source (On Linux)

To install PyQt5 from source, you have to do the following:

As you might know, PyQt5 is a Python binding for the famous library Qt that is written in C++.

The tool that makes this binding is called SIP. So in order to install PyQt5 from source, you need at first to install SIP.

To install SIP, run the following command:

$ pip3 install PyQt5-sip

Now you are ready to download and install PyQt5 source.

Download PyQt5 source from here.

Then unpack the compressed source and run the following commands inside the root of the uncompressed folder:
$ make $ make install

1
2
3
4
5
$ python3 configure.py
 
$ make
 
$ make install


To ensure that everything is fine, try to import PyQt5 as we did before and everything should be OK.

Using source (On Windows)

Since SIP needs GCC compiler, you need to install MinGW which is a Windows port of Linux GCC compiler.

The only thing needs to be changed is the configuration step; you need to tell Python about the platform.

This can be done like this:


Congratulations! Now you have successfully installed PyQt5 from source.

 

There are two ways to build GUI apps using PyQt5:

In this PyQt5 tutorial, we will use the PyQt5 designer which makes it so easy to finish a lot of work in a matter of seconds.

PyQt5 designer is shipped with PyQt5 tools. To install it, you need to install PyQt5 tools.

After successful installation, you can find the PyQt5 designer on this location:

Also, If you installed Python for your current user only, you will find the PyQt5 designer on this location:

You can make a shortcut for it instead of going into this location every time you want to run the PyQt5 designer.

 


How to use PyQt5 designer

Open designer.exe and you will see a dialog asking you about the form template you want.

PyQt5 Designer

There are five templates available:

So we have three types of templates, what is the difference?

Difference between QDialog, QMainWindow, and QWidget

 


Load .ui VS convert .ui to .py

In this tutorial, we will use the PyQt5 designer, but before we dig deeper, let’s see how we will use the generated design from the PyQt5 designer.

Open PyQt5 designer, and choose Main Window template and click create button.

Then from the file menu, click save; PyQt5 designer will export your form into XML file with .ui extension. Now, in order to use this design, you have two ways:

Loading the .ui file in your Python code

To load the .ui file in your Python code, you can use the loadUI() function from uic like this:


If you run your code, you should see a window with nothing but a label.

That means the ui file loaded successfully!

We used sys.exit(app.exec()) instead of using app.exec() directly to send the correct status code the parent process or the calling process.

If you used app.exec() directly, the application will send zero which means success and this will happen even if the application crashed.

Converting the .ui file to a .py file using pyuic5

Now, let’s try the second way by converting the .ui file to a Python code:

Yes! A new file was created with the name mydesign.py. Now, let’s import that file to show our window.

The pyuic5 stands for Python user interface converter version 5.


If you run this code, you should see the same window again as we did in the first method.

The benefit of using the second method is the auto-completion that the IDE will provide since all of your widgets are imported, while the first method you just load the .ui file and you need to be aware of your widgets names.

Another benefit of using the second method. The speed, since you don’t need XML parsing to load the UI.

So we can say that converting the .ui file to a .py file is safer in coding and faster in loading!Click To Tweet

Now, let’s get our hands dirty and play with the PyQt5 widgets.

 

QLabel widget

To add a QLabel widget to your form, do the following:

Now, save the design to a .ui file and convert it to a .py file and let’s play with the label widget using code.

Change Font

To change the QLabel font, use the setFont() method and pass a QFont to it like this:


If you run this code, you will note that the label does not appear correctly because the size is smaller than the font size we used. So we need to set the label size.

Change size

To change the QLabel size, you need to set its geometry using setGeometry() method like this:


PyQt5 tutorial Label widget change font

Change text

To change the QLabel text, you can use the setText() method like this:


Label widget change text

That was easy! Let’s check some other widgets.

 


QLineEdit widget

The QLineEdit is an editable place where you can accept input from the user. LineEdit has many methods to work with.

I will create a new design with the PyQt5 designer and I’ll add six QLineEdit widgets and I’ll export it to .py file.

Now, let’s see some QLineEdit methods:


QLineEdit

The second QlineEdit, we set the maximum allowed characters to 10 so nothing more is accepted.

The third QlineEdit, we set it to password mode so all your input appears as asterisks.

The fourth QlineEdit, we set it to read-only so you can’t edit its content.

The fifth QlineEdit, we changed the font color using the setStyleSheet() method and we insert the color like web pages CSS values.

The sixth QlineEdit, we changed the background color using the setStyleSheet() method.

The setStyleSheet() method

The setStyleSheet() method can be used with all PyQt5 widgets to change the style.

You can change the following using setStyleSheet() method:

 

QPushButton Widget

Most of your Python programs will have this QPushButton widget. You click the button and some code is executed.

If you have a programming background, you may hear about event handling where you interact with a widget and a function is executed.

The idea in PyQt5 is the same but the definitions are a bit different.

The click event in PyQt5 is called a signal and the method which gets executed is called a slot.Click To Tweet

So when you click a QPushButton, a signal is emitted. The signal name in this case is called clicked().

In order to bind the emitted signal with a slot, you need to use the connect() method as you will see now.

This event handling process continues to work until you close your form or main widget.

Let’s build a form with a QLabel and a QPushButton and export it to a .py file.

Now, We will connect the clicked() signal with a slot using connect() method like this:

The btnClicked here is the slot or the function that will be executed when you click the QPushButton.

So your code will be like this:


Awesome!

 


Visual signal/slot editor

We saw how to connect the widget signal to a slot using the connect() method, but this is not the only way.

Actually, there are some predefined slots for each widget. You can connect a signal to any predefined slot without coding in the PyQt5 designer.

Drag a QPushButton and a QLineEdit on your form.

Press F4 and drag the mouse from the QPushButton and release it on the top of the QLineEdit.

The signal/slot editor will show up.

Connection editor

On the left, the predefined signals while on the right the predefined slots. Let’s say that we want to connect the clicked() signal with the clear slot.

Choose the clicked from the left and choose clear from the right and click OK.

Now, if you run this form and click the QPushButton, any text on the QLineEdit will be cleared. You can edit or delete this connection from the signal/slot editor panel.

 

How to emit a signal

We saw how signals and slots work. All signals we worked with are predefined for us.

What about emitting our own custom signal?

Very easy! You can do that by using the pyqtSignal class as follows:

Let’s say we have a nut class and we want to fire the cracked signal to be emitted when we crack it.


 

How to use a signal

Now, let’s make our example more practical by instantiating an instance of the nut class and emitting the cracked signal:


The cracked signal was successfully emitted.

Signal (event) overriding

Sometimes, you need to override the default behavior for a specific signal or event.

Let’s see a practical example for that. If you want to close the main window when the user presses a specific key, you can override the keyPressEvent inside your main window like this:


Now if the user presses the F12 key, the main window will be closed.

Here we override the key press signal of the main window and close the window.

 

QComboBox widget

Instead of letting the user enter values in a QLineEdit or any editable widget, we can use a QCombobBox widget to give the user a list of choices to select from.

Let’s drag a combo box to our form and take a look at some of its methods.

If you run the app now, you will note that the QComboBox is empty. To add items to the QComboBox, use the addItem() method:


QComboBox additem

Get all items

There is no direct method to get all items from a QComboBox, but you can use a for loop to do that.


 

Select an item

To select an item from the QComboBox, you have two methods:


Note that when selecting an item by text; make sure you write the correct text otherwise. The QComboBox will stay at the first element.

 

QTableWidget

If you want to view your database data in a tabular format, PyQt5 provides the QTableWidget for that.

QTableWidget consists of cells, each cell is an instance of QTableWidgetItem class.

Let’s design a form that contains a QTableWidget and a QPushButton. Drag a table widget and a push button from the widget box. Then save and convert the design to use it.

To add rows to the QTableWidget, you can use the setRowCount() method.

To add columns to the QTableWidget, you can use the setColumnCount() method.


QTableWidget

Now you can type text manually inside QTableWidget cells.

Clear QtableWidget content

To clear QTableWidget content, you can use the clear method like this:


QTableWidget add text

Populate QTableWidget by code

To fill QTableWidget programmatically, you should use the setItem() method for each QTableWidgetItem.


QTableWidget populate QtableWidget

Make QTableWidget not editable (read-only)

You may not like leaving your table cells editable for the user in some cases. Like showing a read-only data and any editing process makes no sense.

To make QTableWidget not editable, you can use setFlags() method to set each  QTableWidgetItem not editable.

You must set the flags before setting your cell content.

Therefore, your code will be like this:


Now, if you try to edit any cell, you can’t; because the QTableWidgetItem is not editable.

Set QTableWidget column (header) name

Until now, the column names of the QTableWidget are numbers. What about setting the column names to something else.

To set QTableWidget header text, you can use setHorizontalHeaderLabels() method like this:


QTableWidget set column header text

The same way, you can change the row header by using setVerticalHeaderLabels() method:

You can make your QTableWidget sortable by using the setSortingEnabled() method.

Now, if the user clicks on any column header, he can sort the data in ascending or descending order.

You can use this method before or after populating the QTableWidget with data.

What about sorting the QTableWidget to a specific column only?

You can use the sortByColumn() method and set the column index and the sorting order like this:


Also, you can use the sortItems() method to sort QTableWidget in ascending order by default.

Or you can specify the sorting order:

Keep in mind that if you want to sort your columns programmatically, you must use the sorting methods after populating the QTableWidget with data otherwise, your data won’t be sorted.

 

Add QComboBox in QTableWidget

You may need the user to choose a value inside the QTableWidget instead of entering a text.

What about adding a QComboBox inside QTableWidgetItem?

To add a QComboBox inside QTableWidgetItem, you can use the setCellWidget() method:


QTableWidget add QComboBox

Cool!

Don’t stop your mind from imagination and try to insert different widgets like a QCheckbox or even a QProgressBar.

The above code will be the same except the line where you create the QComboBox, you will add the widget you want.

QTableWidget add QProgessBar

The only limit is your imagination.

Packaging Python files (Converting to executable)

You can convert your Python programs into binary executables using many tools.

For me, I will use pyinstaller which is capable of packaging or freezing Python code into executable under Windows, Linux, Mac OS X, FreeBSD, and Solaris. All this with full support for 32,64-bit architecture.

The best part about pyinstaller the full support for PyQt5.

Great! First, install pyinstaller:

After you installed it, you can convert your Python programs like this:

Your executable will be generated on a folder called dist on your Python program directory.

As you will be, a lot of dependencies generated beside the executable. What about making it one file?

You can generate one executable file using one file mode like this:

Each time you run your executable a console window appears, what about hiding this window?

You can use -w or –noconsole to hide the console window:

This option for Windows and Mac OS X only.

Pyinstaller provides a lot of options to pack your app, to list all options, use –help:

I tried to keep everything as simple as possible. I hope you find the tutorial useful.