Delphi Python For Delphi VCL vs PyQT Comparison

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,203
Credits
4,034
Python For Delphi VCL vs PyQT Comparison
February 16, 2021 By Muhammad Azizul Hakim

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.

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 Для просмотра ссылки Войди или Зарегистрируйся for your platform. Follow the Для просмотра ссылки Войди или Зарегистрируйся installation instructions mentioned Для просмотра ссылки Войди или Зарегистрируйся. Alternatively, you can check out the easy instructions found in this video Для просмотра ссылки Войди или Зарегистрируйся 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 Для просмотра ссылки Войди или Зарегистрируйся.

Here are some working example of it, runs on RAD Studio:
1613499430996.png
Demo01 to Run any Python Scripts on Delphi.

Using Threads inside Python:
1613499452025.png
Demo33: Using Threads inside Python

Using Events in TPythonModule or TPythonType:
1613499467658.png
Demo21: 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:
  1. Install PyQt using pip or easy install:
Код:
pip install PyQt5
See the installation progress in your command line:
1613499500411.png
2. If you want to build the GUI using drag and drop tools, install the pyqt5-tools using pip:
Код:
pip install pyqt5-tools
See the installation progress in your command line:
1613499526603.png
. 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
1613499538742.png
4. Run this simple example in your favorite IDE (i.e. PyScripter), if you want to try PyQt without drag-and-drop tools:
Python:
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:
1613499573264.png
5. Bonus: You can browse the sample application that shows the most common PyQt widgets, from this Для просмотра ссылки Войди или Зарегистрируйся. Here is the screenshot, after running the main.py in PyScripter IDE:
1613499584378.png