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 Pyforms GUI.
Table of Contents
1. What is 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:
Let’s try this interesting Demo, Demo31: Using WrapDelphi to access Delphi Form attributes. This demo shows you various attributes in the Delphi VCL Form:
2. What is Pyforms GUI?
Pyforms GUI is part of the Pyforms framework. Pyforms GUI is a Python 3 framework to allow pyforms applications to execute in Windows GUI mode.
This framework aims to boost the development productivity by providing an API in Python to allow the execution of applications developed for GUI and Web mode in terminal mode.
Pyforms GUI developed by Ricardo Ribeiro from Champalimaud Scientific Software Platform.
How can we use Pyforms GUI?
The steps for using the GUI package Pyforms are:
- Install Pyforms using pip or easy install (note: it will very much easier to install in Anaconda Distributions, because Pyforms GUI will require OpenCV, and other Data Science/Machine Learning packages that have higher compatibility with Anaconda Distributions):
pip install pyforms-gui
See the installation progress in your command prompt:
2. Create your first app.
Create the file demo.py and add the following code:
from pyforms.basewidget import BaseWidget
from pyforms.controls import ControlFile
from pyforms.controls import ControlText
from pyforms.controls import ControlSlider
from pyforms.controls import ControlPlayer
from pyforms.controls import ControlButton
def __init__(self, *args, **kwargs):
super().__init__('Computer vision algorithm example')
#Definition of the forms fields
self._videofile = ControlFile('Video')
self._outputfile = ControlText('Results output file')
self._threshold = ControlSlider('Threshold', default=114, minimum=0, maximum=255)
self._blobsize = ControlSlider('Minimum blob size', default=110, minimum=100, maximum=2000)
self._player = ControlPlayer('Player')
self._runbutton = ControlButton('Run')
#Define the function that will be called when a file is selected
self._videofile.changed_event = self.__videoFileSelectionEvent
#Define the event that will be called when the run button is processed
self._runbutton.value = self.__runEvent
#Define the event called before showing the image in the player
self._player.process_frame_event = self.__process_frame
#Define the organization of the Form Controls
self._formset = [
When the videofile is selected instanciate the video in the player
self._player.value = self._videofile.value
def __process_frame(self, frame):
Do some processing to the frame and return the result frame
After setting the best parameters run the full algorithm
if __name__ == '__main__':
from pyforms import start_app
Execute the demo.py file in the command prompt, using this command:
Let’s see the interesting results:
This GUI can even run a video inside it!
Congratulations, you already learn the amazing example of GUI development by Python4Delphi vs Pyforms GUI!
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!