Sometimes your application needs a user interface with professional looks, but what is the best way to make one for Python applications? Try DelphiVCL for Python!
DelphiVCL is a Python module giving Python GUI apps on Windows access to Delphi’s VCL for robust and high-performance native Windows visual widgets. It uses the Python4Delphi library as a bridge between Delphi’s VCL (Visual Component Library) and Python. DelphiVCL is currently available for Windows.
The DelphiVCL Python module makes ‘the whole VCL’ available in Python! No Delphi or Object Pascal experience or knowledge is necessary for you as a Python developer to take full advantage of the Native GUI benefits.
How can we use DelphiVCL?
These are the steps for using the DelphiVCL:
1. Installing DelphiVCL
There are two ways for you to install DelphiVCL: By directly copying the module to your local/system path, or install it via pip.
1.1. Copy to Your Local or System Path
- Download the DelphiVCL.pyd module Beta Release 0.01– Beta preview – 2021-18-01, and extract according to your Python version and bit.
- You will need to place the DelphiVCL.pyd to your default path for your Python packages/libraries. For example:
if you use Anaconda Distributions.
1.2. Install via pip
- Run easy-install by pip in your Command Prompt, using the following command:
pip install -i https://test.pypi.org/simple/ DelphiVCL-lucioricVCL
(PIP installation is currently in the testing stage of development and will change in the near future. Check the DelphiVCL home page for more information.)
The installation progress in your Command Prompt:
2. Run a Simple Form Example
In essence, DelphiVCL is a wrapper that helps to create and access Delphi Objects quickly from Python. These wrappers contain container classes to extend and expose your custom events, methods, variables that can be used in Python script.
Here is a Python code sample using DelphiVCL to create a simple Form app with a list, edit, and button:
from DelphiVCL import *
def __init__(self, Owner):
self.Caption = "A VCL Form..."
self.SetBounds(10, 10, 340, 410)
self.lblHello = Label(self)
self.lblHello.SetProps(Parent=self, Caption="Please Input Your Lists")
self.edit1 = Edit(self)
self.edit1.SetProps(Parent=self, Top=30, Left=10, Width=200, Height=24)
self.button1 = Button(self)
self.button1.SetProps(Parent=self, Caption="Add", OnClick=self.Button1Click)
self.lb1 = ListBox(self)
def Button1Click(self, Sender):
Application.Title = "My DelphiVCL App"
f = MainForm(Application)
Here is the GUI created by the Python code above. You can run it using your favorite Python IDE, which for me is PyScripter:
Or you can save the script first, and run it through the command line using this command:
This GUI expects user inputs. Clicking the button will add the text from the edit box to the list box:
Congratulations, you already learn the powerful example of accessing Delphi’s VCL functionalities and features from Python, using DelphiVCL Modules.
Now it’s time for you to try it yourself, and please share your experiences in the comment section below.