
This Section will break down the code example to create a simple Form app as presented in Section 5. 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 Section 5:
- Import the module:
1 |
from DelphiVCL import * |
- Use the Python variables, set methods which are included in DelphiVCL classes (review the Section 4 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) |
Check out DelphiVCL which easily allows you to build GUIs for Windows using Python.
Watch this comprehensive introduction to Python GUI Development with DelphiVCL library video by Jim McKeeth: