CodeDelphiDelphiVCLLearn PythonPythonPython GUIRAD StudioWindows

Quickly Build Ultra-Modern Python Native Windows GUIs With Delphi

pythongui

Sometimes your application needs a user interface, but what is the best way to make one for Python applications? Enter DelphiVCL for Python. The VCL is a mature Windows native GUI framework with a huge library of included visual components and a robust collection of 3rd party components. It is the premier framework for native Windows applications, but how to use it with Python? Thanks to the DelphiVCL Python package (based on the open-source Python4Delphi library), the VCL is a first-class package for building native Windows GUIs with Python. Need more design tools? You can build the entire GUI in Delphi and then write all the logic in Python. 

Why Native GUI is Important:

  • Performance: Windows provides hardware acceleration for native controls.
  • Windows Handles: Native Windows controls have Windows handles providing better OS and intra-application integration.
  • Consistent Behavior: The use of native controls gives users consistent behavior between all applications they use.
  • Microsoft Active Accessibility (MSAA) is the framework that leverages native controls to provide accessibility interfaces like screen readers

Popular Python GUI Frameworks

Tkinter (TK Interface) –  The default Python GUI Available under the Python license, uses Tcl/Tk cross-platform widgets. Tk is implemented in C and some Tcl. Supports various styles but No OS style integration. Tkinter sample,

tkinter-2034107
Tkinter Form

PyQt (pie-cute) – Binding for the cross-platform Qt widget library. Originally by Trolltech (1991) and Nokia (2008). Qt is a set of C++ libraries and development tools that includes Cross-platform abstractions for GUI, Networking, threads, regular expressions, SVG, OpenGL,3D animation, etc. PyQT implements over 1000 of these classes as a set of Python Modules.

  • GPL/LGPL license, or Qt Commercial license
  • Must be installed, pip install PyQt5
  • Fusion style option comes close to matching platform look, but still doesn’t use native controls. PyQT Sample.
qt-7610709
PyQT5 Form

Other Python GUI Frameworks.

  • PySide – Python Qt bindings project, providing access to complete Qt4.8 framework as well as generator tools for rapidly generating bindings for any C++ libraries.
  • wxPython – Cross-Platform GUI Python library. It is implemented as a set of Python extension modules that wrap GUI components of the wxWidgets cross-platform library written in C++
  • PyGTK – Binding for GTK (GNOME). GTK is a widget toolkit.
  • Kivy – Focused on mobile and cross-platform.

Delphi & VCL

  • Object Pascal(Delphi) is an extremely powerful language based upon core foundations such as a good program structure and extensible data types. These foundations are partially derived from the traditional Pascal language, but even the core language features have seen many extensions from the early days.  Download a copy of the Object Pascal Handbook by Marco Cantu…FREE! .
  • VCL Windows-specific VCL (Visual Component Library) is a set of components and classes for the rapid development of Windows applications in the Delphi and C++ languages.
  • The GUI components of the VCL are native Windows GUI components.

Python4Delphi & Embarcadero Delphi

  • Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi. Easily execute Python scripts, create new Python modules and new Python types. 
  • Can create Python extensions as DLLs and provides different levels of functionality:
    • Low-level access to the python API
    • High-level bi-directional interaction with Python
    • Access to Python objects using Delphi custom variants (VarPyth.pas)
    • Wrapping of Delphi objects for use in python scripts using RTTI (WrapDelphi.pas)
    • Creating python extension modules with Delphi classes and functions
  • Design Beautiful Desktop and Mobile App UIs with Embarcadero Delphi
  • Code Faster and Smarter with Delphi inbuilt and Rich 3rd party Ecosystem. 
  • Debug Faster with Integrated Native Debugging
  • Compile and Deploy High-Performance Native Apps
  • Easily Improve the Quality of Your Code, Collaborate and Extend the IDE

DelphiVCL For Python

  • DelphiVCL  for Python is nothing but the wrapping of Delphi objects for use in python scripts using RTTI (WrapDelphi.pas) explicitly for VCL Components(WrapDelphiVCL.pas)
  • Wrappers help to create and access Delphi Objects quickly from python. 
  • These wrappers contain container classes to extend and expose your custom events, methods, variables which can be used in python script.

How to Build DelphiVCL for Python

  1. Check the video for how to extend Delphi Objects as a Python Extension module Combining the strengths of Delphi and Python – Python4Delphi replay part 2 from 46.03 minutes.
  2. Alternatively, we can check the blog post, How to extend PythonModule as a DLL using Python4Delphi. In a similar fashion, a simple Python Module DelphiVCL is created which wraps all the Delphi VCL objects.

Note: For Python developers, it’s less important how to build this DelphiVCL Python Extension Module, rather can learn on available VCL objects and their properties to quickly develop a GUI application. Similar to the Tkinter and PyQt sample app mentioned above, the DelphiVCL sample app is below.

delphivcl-8346911
DelphiVCL Form

Comparing the Forms of different Frameworks.

Styling :

coparision1-8364384

OS integration’s :

comparision2-4853228

Apart from these Delphi VCL uses Uses Windows controls and each control has a handle that supports UI testing. None provide native Windows controls or Windows platform integration.

How to run a DelphiVCL sample.

  1. Download DelphiVCL.7z and extract according to the python version. Where the DelphiVCL.pyd and the sample TestVCL.py found in the extracted folder.
  2. From the command prompt, navigate to the folder mentioned in step 1. Provide the Pythopn.exe path space DelphiVCL python script. Press the Enter key. e.g) C:DelphiVCLDelphiVCL.64bit-39>C:PythonPython39python.Exe TestVCL.py
  3. For more VCL components demonstration Download the Delphi4Python.zip folder and extract it. Run the samples Delphi4PythonSample.py and Delphi4PythonComponentsSample.py similar to step 2. Note. This Delphi4Python.pyd is built with Python39.dll

VCL Visual Designers

  • The Form Designer (or Designer) is displayed automatically when you are creating or editing a graphical application that uses a form file, either a .dfm or an .fmx file.
  • A VCL form displays the standard Windows buttons for Minimize, Resize, and Close commands. Drag and Drop components from ToolPallete and you can view and set properties and events visually using ObjectInspector
  • Ultimate Design Guidelines Support with VCL Components.
  • Taking a Snapshot of Your Form (VCL Only)
  • LiveBindings is a data-binding feature supported by both the VCL and FireMonkey frameworks. It is an expression-based framework, which means it uses bindings expressions to bind objects to other objects or to dataset fields.
  • Create new LiveBindings between various visual components you have on your form.
  • Edit the existing LiveBindings.
  • Visualize all the LiveBindings that you have created.
  • Export your binding diagram as an image file.

With the help of VCL Visual Designers, you can easily develop GUI quickly which later can be wrapped using Python4Delphi and extended as Python Module similar to DelphiVCL. Download the DelphiVCLWebinar.zip folder where you can learn how to wrap custom VCL forms using RAD studio. Note. This is built with Python39.dll and using Rad Studio 10.4.1

References

Delphi VCL DockWiki’s 

Python4Delphi Resources:

Blog Resources:

YouTube Embarcadero channel link:

Python4Delphi

Downloads

Summary

  • Learning Delphi and Building Native GUI apps is Easier and faster.
  • Quite a lot of resources with a Rich third-party ecosystem are available to get started.
  • Python has vast packages to ease developers from basic programming tasks to advanced Scientific, ML, AI, Deep learning-related tasks.  
  • Combining the Strengths of Delphi and Python helps users to build Ultra-fast Native GUI Apps.
close
Related posts
Learn PythonPythonPython GUIVideos

Learn Python With Transitioning From Developing Software to Developing People by Matthew Knapp Bachman (PyCon 2020) Video

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

Decipher the DelphiVCL.Application

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

Create a Very Basic Empty Form using DelphiVCL.Form

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

An Introduction To DelphiVCL: A Python GUI Builder For Windows

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

it_ITItalian