This post will break down the code example to create a simple Form app as presented in the previous post. These steps are essential for Python Developers to be familiar with Delphi VCL methods, events, and properties, to enable you in creating professional Windows Apps, without installing Delphi.
Below are the explanations of code example in the previous post:
- Import the module:
1 |
from delphivcl import * |
- Use the Python variables, set methods which are included in DelphiVCL classes (review this post to see all available methods), like:
Form
,Edit
,Button
,ListBox
,Application
, etc to create Python Objects. See the examples below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# Set the Form method as MainForm class class MainForm(Form) # Set the Edit method self.edit1 = Edit(self) # Set the Button method self.button1 = Button(self) # Set the ListBox method self.lb1 = ListBox(self) # Set the Application method to encapsulate a windowed application. The Application method reflects the fundamentals established in the Windows operating system to create, run, sustain, and destroy an application. def main(): Application.Initialize() Application.Title = "My DelphiVCL App" f = MainForm(Application) f.Show() FreeConsole() Application.Run() main() |
- Use the Python variables to set events for needed actions. In this example, a button click for adding items:
1 2 |
def Button1Click(self, Sender): self.lb1.Items.Add(self.edit1.Text) |
- Set the properties of Python Objects using
SetProps(propertyname = propertyvalue,...N)
or each property one by one. Define events and custom methods required to manipulate the GUI events and operations in the script. Here is the example:
1 2 3 4 5 6 7 8 |
# Set the Caption for the Window self.Caption = "A VCL Form..." # Set the size of the Window self.SetBounds(10, 10, 340, 410) # Set the properties for the Button method self.button1.SetProps(Parent=self, Caption="Add", OnClick=self.Button1Click) |
Table of Contents
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 * |
Watch this comprehensive introduction to Python GUI Development with DelphiVCL library video by Jim McKeeth:
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.
References & further readings
[1] Anbarasan. (2021).
Quickly Build Ultra-Modern Python Native Windows GUIs With Delphi. PythonGUI.org. Embarcadero Technologies. pythongui.org/quickly-build-ultra-modern-python-native-windows-guis-with-delphi