![pexelsphoto63258926389397 → Python GUI photo of man smiling in front of his laptop](https://i0.wp.com/pythongui.org/wp-content/uploads/2021/02/pexels-photo-6325892-6389397.jpeg?resize=867%2C694&ssl=1)
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:
![19411561 → Python GUI 1 9411561](https://i0.wp.com/pythongui.org/wp-content/uploads/2021/02/1-9411561.png?resize=750%2C144&ssl=1)
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:
![delphivcl output on pyscripter ide → Python GUI delphivcl output on pyscripter ide](https://i0.wp.com/pythongui.org/wp-content/uploads/2021/04/output1_onIDE-5924229.png?resize=750%2C400)
Or you can save the script first, and run it through the command line using this command:
1 |
python.exe delphiVCLSample.py |
![delphivcl output from cmd → Python GUI delphivcl output from cmd](https://i0.wp.com/pythongui.org/wp-content/uploads/2021/04/output2_fromCMD-6400405.png?resize=750%2C401)
This GUI expects user inputs. Clicking the button will add the text from the edit box
to the list box
:
![output delphivcl gui example → Python GUI output delphivcl gui example](https://i0.wp.com/pythongui.org/wp-content/uploads/2021/04/output3_guiExample-3914997.png?resize=329%2C404)
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.
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.