Delphi Getting Started with DelphiVCL: Simple Windows Form Example In Python

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Getting Started with DelphiVCL: Simple Windows Form Example In Python
By Muhammad Azizul Hakim March 8, 2021

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:
Код:
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()
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:
1615241832794.png
Or you can save the script first, and run it through the command line using this command:
Код:
python.exe delphiVCLSample.py
1615241850140.png
This GUI expects user inputs. Clicking the button will add the text from the edit box to the list box:
1615241860096.png