To increase your familiarity with DelphiVCL Components, this post will show you a demo that presents commonly used VCL components, and call them one-by-one with Python.
The following is a Python code sample using DelphiVCL4Python:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
from delphivcl import * class MainForm(Form): def __init__(self, Owner): self.Caption = "Components Overview Sample" self.Name = "BaseForm" self.SetBounds(10, 10, 700, 650) # pnlMain = CreateComponent('TPanel',Owner) pnlMain.SetProps(Parent=self, Caption="",align = "alClient", Name = "MainPanel") # page control creation pgConMain = PageControl(pnlMain) pgConMain.Name = "MyPageControl" pgConMain.Parent = pnlMain pgConMain.Align = "alClient" # Tabsheet one pgOne = TabSheet(pnlMain) pgOne.PageControl = pgConMain pgOne.Caption = "StandardControls" # label Creation lblHello = CreateComponent('TLabel',pgOne) lblHello.Parent = pgOne lblHello.Caption = 'FirstName' lblHello.Name = 'Name' lblHello.Left = 20 lblHello.Top = 14 lblHello.Width = 121 lblHello.Height = 30 # Edit box creation edtHello = CreateComponent('TEdit',pgOne) edtHello.Parent = pgOne edtHello.Text = 'Jim' edtHello.Name = 'edtFirstName' edtHello.Left = 145 edtHello.Top = 14 edtHello.Width = 121 edtHello.Height = 30 chkSingle = CheckBox(self) chkSingle.Parent = pgOne chkSingle.Caption = 'Single ?' chkSingle.Alignment = 'taLeftJustify' chkSingle.SetBounds(20, 44, 141, 30) # label Creation lblCountry = CreateComponent('TLabel',pgOne) lblCountry.SetProps(Parent=pgOne,Caption='Country') lblCountry.SetBounds(20,88,121,30) #listbox lboxCountry = ListBox(pgOne) lboxCountry.SetProps(Parent=pgOne) lboxCountry.SetBounds(145,88,121,60) lboxCountry.Items.Add('RUSSIA') lboxCountry.Items.Add('USA') lboxCountry.Items.Add('INDIA') lboxCountry.Items.Add('AUSTRALIA') # label Creation lblDateOfIssue = CreateComponent('TLabel',pgOne) lblDateOfIssue.SetProps(Parent=pgOne,Caption='Date Of Birth') lblDateOfIssue.SetBounds(20,162,121,30) dtpDateofIssue = CreateComponent('TDateTimePicker',pgOne) dtpDateofIssue.SetProps(Parent=pgOne) dtpDateofIssue.SetBounds(145,162,121,30) # label Creation lblCity = CreateComponent('TLabel',pgOne) lblCity.SetProps(Parent=pgOne,Caption='City') lblCity.SetBounds(20,206,121,30) #Combobox cbxCity = ComboBox(pgOne) cbxCity.SetProps(Parent=pgOne,Name='ComboBox') cbxCity.SetBounds(145,206,121,60) cbxCity.Items.Add('New York') cbxCity.Items.Add('Sydney') cbxCity.Items.Add('Banglore') cbxCity.Items.Add('Tokyo') def ChangeHandler(sender): memoEvent.Lines.Add('changed') cbxCity.OnChange = ChangeHandler # Radiogroup Creation rbgRadioBox = RadioGroup(pgOne) rbgRadioBox.SetProps(Parent=pgOne,Caption='Gender') rbgRadioBox.SetBounds(20,250,242,90) rbgRadioBox.Items.Add('Male') rbgRadioBox.Items.Add('Female') #Button btnOK = Button(pgOne) btnOK.SetProps(Parent=pgOne,Caption = 'Submit',Name = 'btnOK') btnOK.SetBounds(145,540,60,30) #Memo memoEvent = Memo(pgOne) memoEvent.SetProps(Parent=pgOne) memoEvent.SetBounds(300,14,350,300) def ClickHandler(Sender): memoEvent.Lines.Add(Sender.Name + ' clicked') btnOK.OnClick = ClickHandler # Tabsheet two pgTwo = TabSheet(pnlMain) pgTwo.PageControl = pgConMain pgTwo.Caption = "Ext controls" shpRectangle = Shape(pgTwo) shpRectangle.SetProps(Parent=pgTwo,Shape = 'stRectangle') shpRectangle.SetBounds(140,14,400,200) clbSelect = ColorBox(pgTwo) clbSelect.SetProps(Parent=pgTwo) clbSelect.SetBounds(20,14,100,30) def ColorChangeHandler(Sender): shpRectangle.Brush.Color = clbSelect.Selected clbSelect.Onchange = ColorChangeHandler grdTest = DrawGrid(pgTwo) grdTest.Parent = pgTwo grdTest.SetBounds(20, 220, 520, 180) def grdTestDrawCell(Sender, Col, Row, Rect, State): if gdSelected in State: Sender.Canvas.Brush.Color = clBlue # 0x00ff0000 # blue Sender.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, "%d @ %d" % (Col, Row)) def grdTestSelectCell(Sender, Col, Row, CanSelect): if Col == 2 and Row == 2: CanSelect.Value = False grdTest.OnDrawCell = grdTestDrawCell grdTest.OnSelectCell = grdTestSelectCell self.OnClose = self.MainFormClose def MainFormClose(self, Sender, Action): Action.Value = caFree def btnOKClick(self, Sender): btnOK.Caption = "Clicked" def main(): Application.Initialize() Application.Title = "MyDelphiApp" f = MainForm(Application) f.Show() FreeConsole() Application.Run() Application.Destroy() main() |
Here is the GUI created by the Python code above:
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