How to Make an App with Python? Quick Guide for Desktop Applications

Python's simplicity and beginner-friendly nature make it an excellent choice for desktop application development. Unlike mobile or web development, creating a Python desktop app requires fewer dependencies and offers more direct access to system resources. Additionally, Python's rich ecosystem of libraries and frameworks provides everything you need to build functional, professional-looking applications.
In this quick start guide, you'll learn how to create a desktop app with Python using PyQt and QML. We'll walk through the entire process, from setting up your development environment to packaging your finished application for distribution. By the end, you'll have the skills to transform your Python code into standalone software that users can install and run on their computers.
Ready to build your first Python desktop application? Let's dive into the tools you'll need to get started.
Choose the Right Tools for Your Python Desktop App
When building a Python desktop application, selecting the right tools significantly impacts your development experience and final product quality. Let's explore the optimal toolkit for creating professional desktop applications with Python.
Why PyQt is preferred over Tkinter
While Tkinter comes bundled with Python, making it accessible for beginners, PyQt offers considerable advantages for serious application development. PyQt is a comprehensive GUI framework built around the C++ Qt framework, providing a complete application development ecosystem rather than just a GUI library.
PyQt excels over Tkinter in several key areas:
-
Modern appearance - PyQt applications have a native look and feel on all supported platforms
-
Advanced features - Beyond basic widgets, PyQt offers MVC data views, database interfaces, graph plotting, vector graphics, and multimedia support
-
Performance - PyQt delivers better performance compared to Tkinter, making it suitable for larger projects
-
Professional quality - Ideal for commercial-quality software and complex applications
The main trade-off is PyQt's steeper learning curve, but you can focus only on the components your project needs. Furthermore, PyQt's extensive documentation and robust capabilities make it worth the additional effort.
Installing PyQt6 using pip
Setting up PyQt6 is straightforward. For Windows, macOS, or Linux, simply run:
pip install pyqt6
This command downloads and installs the PyQt6 library from PyPI for your specific platform and Python version. After installation, verify it worked by running Python and importing PyQt6.
For Raspberry Pi users, currently only PyQt5 is supported, which can be installed using:
sudo apt-get install python3-pyqt5
Note that the Qt framework will be installed automatically as a dependency.
Setting up your project folder
Organizing your project properly from the start helps maintain clean, maintainable code as your application grows. First, create a dedicated directory for your project with separate folders for:
-
Source code
-
Resources (images, icons, sounds)
-
QML files (for UI design)
-
Documentation
Start with a basic structure that includes a main.py file as your entry point. If you want to use Qt Designer for visual UI creation, you'll need to download it separately from the Qt website. This tool significantly simplifies interface design through its drag-and-drop functionality.
For more advanced projects, consider adding virtual environment files and a requirements.txt file to track dependencies, consequently making your project easier to share and deploy.
Build Your First App with PyQt and QML
Now that you have PyQt6 installed, it's time to create your first desktop application. Building a basic app requires two main components: a Python file to handle the application logic and a QML file for the user interface.
Writing the main.py file
First, create a new file named main.py in your project directory. This will serve as the entry point for your application. Add the following code:
import sys
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtQml import QQmlApplicationEngine
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
engine.load('main.qml')
sys.exit(app.exec())
The code above creates a QGuiApplication instance, which manages application-wide settings. The QQmlApplicationEngine loads and runs QML files. Notably, connecting the engine's quit signal to the app's quit function ensures both close together properly.
Creating a basic QML UI
Next, create a file named main.qml in the same directory as your Python file. This will define your user interface:
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
visible: true
width: 600
height: 500
title: "HelloApp"
Text {
anchors.centerIn: parent
text: "Hello World"
font.pixelSize: 24
}
}
This QML code creates a window with specific dimensions and a centered text element. The visible: true property is essential—without it, your UI would run but remain invisible to users.
Running your first desktop app
Once you've saved both files, open your terminal or command prompt, navigate to your project directory, and execute:
python main.py
Upon running this command, you'll see a window appear with "Hello World" displayed in the center. Indeed, this simple app demonstrates the foundation for more complex applications.
Although basic, this application showcases the core structure you'll use for any PyQt/QML project: Python handles the application logic, whereas QML defines the user interface elements and their layout.
Add Features: UI, Time, and Data Flow
Package and Distribute Your App
After developing your Python desktop application with the features you need, the final step involves preparing it for distribution to users. At this stage, you transform your code into a standalone executable that runs without requiring Python or any dependencies to be installed.
Making the window frameless
Creating a professional-looking application often requires removing the standard window frame and designing a custom title bar. To create a frameless window in PyQt, modify your main window class:
from PyQt6.QtCore import Qt
from PyQt6.QtWidgets import QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowFlags(Qt.WindowType.[FramelessWindowHint](https://www.pythonguis.com/tutorials/custom-title-bar-pyqt6/))
self.resize(400, 200)
The setWindowFlags() method with the FramelessWindowHint parameter removes the default operating system window decoration. However, since frameless windows cannot be moved by default, you need to implement mouse event handlers:
def mousePressEvent(self, event):
self.dragPos = event.globalPosition().toPoint()
def mouseMoveEvent(self, event):
self.move(self.pos() + event.globalPosition().toPoint() - self.dragPos)
self.dragPos = event.globalPosition().toPoint()
event.accept()
This code enables dragging the window by clicking anywhere on it.
Using PyInstaller to build the app
PyInstaller packages your Python application into a standalone executable that contains your code, the Python interpreter, and all required libraries. Initially, install PyInstaller through pip:
pip install pyinstaller
Subsequently, navigate to your project directory and run:
[pyinstaller main.py](https://pyinstaller.org/en/v4.1/usage.html)
This command analyzes your script, creates a .spec file, and builds the application. By default, PyInstaller creates a folder-based distribution in the dist directory.
For a single-file executable that's easier to distribute, use:
pyinstaller --onefile main.py
The --onefile option bundles everything into a single executable file. Moreover, to create a windowed application (no console), add the --windowed flag:
pyinstaller --onefile --windowed main.py
Adding resources and editing the .spec file
During the build process, PyInstaller generates a .spec file that defines how your application is packaged. To include additional files like images or configuration files, modify this spec file:
-
First, generate the spec file without building:
pyi-makespec main.py -
Edit the resulting
main.specfile to add data files:a = Analysis(
['main.py'],
pathex=['/path/to/your/app'],
binaries=[],
datas=[('images/*.png', 'images'), ('config.json', '.')],
hiddenimports=[],
...
)
The first element in each tuple specifies the source file(s), and the second indicates the destination folder in the packaged app. After editing the spec file, build your application using:
pyinstaller main.spec
Running and testing the final executable
Before distributing your application, thoroughly test the executable. For proper testing:
-
Test on a clean system without Python installed
-
Verify all resources load correctly
-
Check that all features work as expected
If your application fails to run, examine PyInstaller's logs in the build directory. For debugging issues, rebuild with additional options:
pyinstaller --debug=all main.py
This provides detailed information about imports and execution. Alternatively, if specific modules aren't found, use the --hidden-import option:
pyinstaller --hidden-import=module_name main.py
Once tested, your Python desktop application is ready for distribution to users who can run it without installing Python or any dependencies—exactly what makes creating apps with Python so powerful for end-user distribution.
Conclusion
Python desktop application development stands as an accessible yet powerful approach to creating functional software. Throughout this guide, you've learned how PyQt offers significant advantages over Tkinter through its modern appearance, advanced features, and professional-quality output. Additionally, you've walked through the complete development process from initial setup to final distribution.
The simplicity of getting started with just a few lines of code makes Python particularly appealing for desktop applications. Nevertheless, this simplicity doesn't limit your ability to create sophisticated software. PyQt and QML together provide a robust foundation for applications that look professional and perform efficiently across different operating systems.
Perhaps most importantly, tools like PyInstaller transform your Python code into standalone executables that users can run without installing Python or dependencies. Therefore, your applications become truly accessible to end users regardless of their technical knowledge. This capability essentially bridges the gap between development convenience and distribution practicality.
Python's versatility extends well beyond the basic examples shown here. Many organizations use Python to build complex desktop applications for data analysis, healthcare, business management, and creative tools. Consequently, the skills you've gained from this guide apply to numerous potential projects.
Remember that effective desktop application development requires thoughtful planning and organization. Start with simple projects to build your confidence, then gradually incorporate more advanced features as you become comfortable with the PyQt framework. Your Python desktop applications will improve with each project you undertake.
Python continues to grow in popularity for good reason - it enables developers to transform ideas into functioning software quickly and efficiently. Now that you understand the fundamentals of Python desktop application development, you're ready to build your own professional-quality apps that users can easily install and enjoy.


