目前使用python主要是开发http api接口,为应用做后端支持,也尝试了使用python做了一些绘图,比如画画五角星啥的;

那么,python在开发桌面应用方面是否一样简单呢?抱着这个目的,去网上搜索了一番,结果发现delphi的一个库,还是emb官方提供的,名称是DelphiVCL4Python和DelphiFMX4Python,使用步骤和效果如下:

安装(我是macOS系统,所以只能使用delphifmx)

pip3 install delphifmx

使用

from delphifmx import *

class HelloForm(Form):

    def __init__(self, owner):

        self.SetProps(Caption = "Hello Python",

            Position = "ScreenCenter", OnShow = self.__form_show)

        self.hello = Label(self)

        self.hello.SetProps(Parent = self, width = 200,

            Text = "Hello Python from Delphi FMX", Position = Position(PointF(20, 20)))

        self.clickme = Button(self)

        self.clickme.SetProps(Parent = self, Text = "Click Me",

            Position = Position(PointF(20, 50)), OnClick = self.__button_click)

    def __form_show(self, sender):

        self.SetProps(Width = 300, Height = 400)

    def __button_click(self, sender):

        self.hello.Text = "Thanks!"

def main():

    Application.Initialize()

    Application.Title = "Hello Delphi FMX"

    Application.MainForm = HelloForm(Application)

    Application.MainForm.Show()

    Application.Run()

    Application.MainForm.Destroy()

if __name__ == '__main__':

    main()

对了,项目开源地址:

https://github.com/Embarcadero/DelphiFMX4Python