Are you an expert in desktop apps and GUI development who want to also work with Python because of its simplicity, flexible use, and growing demand in the market out there? Or are you a Python Developer at any level who wants to start a GUI development journey? This article is for you.
We will review the two examples of the most powerful Python Desktop App and GUI Frameworks: Python For Delphi (P4D) VCL vs PyQT.
Table of Contents
1. Python For Delphi VCL
How about combining the strength of GUI and desktop app development by Delphi with Python for your applications, to provide first-class solutions for your customer needs? Python4Delphi is the answer to your need!
Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi and Lazarus (FPC). They let you easily execute Python scripts, and powerfully create new Python modules and new Python types.
The best advantage of P4D is, it makes it very easy to use Python as a scripting language for Delphi applications that comes with a very extensive range of customizable demos and tutorials that ready to use to develop real-world apps. In shorts: P4D gives you various real-world “Hello World!” apps that ready to adjust to your needs!
Prerequisites: Before you begin to work with Python4Delphi VCL, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in this video Getting started with Python4Delphi and the behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.
Here are some working example of it, runs on RAD Studio:
Using Threads inside Python:
Using Events in TPythonModule or TPythonType:
2. PyQt
PyQt is a port of the Qt library (C++). PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.
Qt is a very powerful GUI library. Qt is a set of cross-platform C++ libraries that implement high-level APIs for accessing many aspects of modern desktop and mobile systems. These include location and positioning services, multimedia, NFC and Bluetooth connectivity, a Chromium-based web browser, as well as traditional UI development.
After creating your app with PyQt, you can create an installation program with fbs.
PyQT is developed by Riverbank Computing Limited and supports Windows, OS X, Linux, iOS, and Android.
How can we use PyQt?
The steps for using the GUI package PyQt are:
- Install PyQt using pip or easy install:
1 |
pip install PyQt5 |
See the installation progress in your command line:
2. If you want to build the GUI using drag and drop tools, install the pyqt5-tools using pip:
1 |
pip install pyqt5-tools |
See the installation progress in your command line:
3. If you want to create GUI using drag-and-drop tools, run designer.exe. You can find the designer from the following sub-path:
C:UsersYourUsernameAppDataLocalProgramsPythonPython39Libsite-packagesqt5_applicationsQtbin
4. Run this simple example in your favorite IDE (i.e. PyScripter), if you want to try PyQt without drag-and-drop tools:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import sys from PyQt5.QtWidgets import * class PyQtLayout(QWidget): def __init__(self): super().__init__() self.UI() def UI(self): self.setGeometry(10, 10, 280, 280) self.move(10, 10) self.setWindowTitle('A Qt Form...') label = QLabel('Hello Python', self) label.move(10, 10) edit = QLineEdit("", self) edit.move(10, 30) edit.resize(170, 20) button = QPushButton("Add", self) button.move(190,28) listView = QListWidget(self) listView.move(10, 60) def buttonClick(): listView.addItem(edit.text()) button.clicked.connect(buttonClick) self.show() def main(): app = QApplication(sys.argv) #QApplication.setStyle(QStyleFactory.create('Windows')) ex = PyQtLayout() sys.exit(app.exec_()) if __name__ == '__main__': main() |
Screenshot of PyScripter:
5. Bonus: You can browse the sample application that shows the most common PyQt widgets, from this repository. Here is the screenshot, after running the main.py in PyScripter IDE:
Conclusion
Congratulations, you already learn the amazing example of GUI development by Python4Delphi vs PyQt!
Now it’s time for you to try it yourself, and please comment below for which one is your favorite that best suits your needs!
Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.