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):
1 |
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:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
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 class ComputerVisionAlgorithm(BaseWidget): 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 = [ ('_videofile', '_outputfile'), '_threshold', ('_blobsize', '_runbutton'), '_player' ] def __videoFileSelectionEvent(self): """ 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 """ return frame def __runEvent(self): """ After setting the best parameters run the full algorithm """ pass if __name__ == '__main__': from pyforms import start_app start_app(ComputerVisionAlgorithm) |
Execute the demo.py file in the command prompt, using this command:
1 |
python.exe demo.py |
Let’s see the interesting results:
This GUI can even run a video inside it!
Conclusion
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!
Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.