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.
Table of Contents
How can we use DelphiVCL?
These are the steps for using the DelphiVCL:
1. Installing DelphiVCL
“Important update on Jan 14, 2022: DelphiVCL release version is finally out on PyPI!”
Watch this comprehensive introduction to Python GUI Development with DelphiVCL library video by Jim McKeeth, for more information:
You can easily install DelphiVCL
using pip
in your Command Prompt:
1 |
pip install delphivcl |
And visit our GitHub for a quick start guide.
2. Installing DelphiVCL beta release (archive)
There are two ways for you to install DelphiVCL
beta release: By directly copying the module to your local/system
path, or install it via pip
.
2.1. Copy to your local
or system
path
- Download the
DelphiVCL.pyd
moduleBeta 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:
1 |
C:/Users/YourUsername/AppData/LocalPrograms/Python/Python39/Lib/site-packages |
Or
1 |
C:/Users/YourUsername/Anaconda3/Lib/site-packages/DelphiVCL |
if you use Anaconda Distributions.
2.2. Install via pip
- Run easy-install by
pip
in your Command Prompt, using the following command:
1 |
pip install -i https://test.pypi.org/simple/ DelphiVCL-lucioricVCL |
The installation progress in your Command Prompt:
3. 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
:
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 |
from delphivcl import * class MainForm(Form): 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.lblHello.SetBounds(10,10,120,24) 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.button1.SetBounds(220,29,90,24) self.lb1 = ListBox(self) self.lb1.SetProps(Parent=self) self.lb1.SetBounds(10,60,300,300) def Button1Click(self, Sender): self.lb1.Items.Add(self.edit1.Text) def main(): Application.Initialize() Application.Title = "My DelphiVCL App" f = MainForm(Application) f.Show() FreeConsole() Application.Run() Application.Destroy() main() |
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:
1 |
python.exe delphiVCLSample.py |
This GUI expects user inputs. Clicking the button will add the text from the edit box
to the list box
:
4. Note for beta release users
In practice, the only difference between DelphiVCL for Python release version and the beta version is only in how you write the DelphiVCL. Here is the example for how you import the library:
- Release version:
1 |
from delphivcl import * |
- Beta version:
1 |
from DelphiVCL import * |
Conclusion
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.
Also, watch the following webinar by Alexey Sharagin to Master the Secrets of Beautiful Modern Windows Apps:
Check out DelphiVCL which easily allows you to build GUIs for Windows using Python.
Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.