
有时您的应用程序需要一个用户界面,但是为Python应用程序制作用户界面最好的方法是什么?输入用于Python的DelphiVCL。VCL是成熟的Windows本机GUI框架,具有庞大的包含的可视组件库和强大的第三方组件集合。它是本机Windows应用程序的主流框架,但是如何在Python中使用它呢?多亏了DelphiVCL Python软件包(基于开源Python4Delphi库),VCL是用于使用Python构建本机Windows GUI的一流软件包。需要更多设计工具?您可以在Delphi中构建整个GUI,然后在Python中编写所有逻辑。
为什么本机GUI很重要:
- 性能: Windows为本机控件提供了硬件加速。
- Windows句柄:本机Windows控件具有Windows句柄,可提供更好的操作系统和应用程序内集成。
- 一致的行为:使用本机控件可使用户在使用的所有应用程序之间保持一致的行为。
- Microsoft Active Accessibility(MSAA)是利用本机控件提供可访问性界面(如屏幕阅读器)的框架
流行的Python GUI框架
Tkinter( TK接口)–默认的Python GUI(在Python许可下可用)使用Tcl / Tk跨平台小部件。Tk在C和某些Tcl中实现。支持各种样式,但不支持OS样式集成。Tkinter样本,泰山老父
import tkinter as tki
class Application(tki.Frame):
def __init__(self, master=None):
super().__init__(master)
self.list = tki.Listbox(self)
self.editb = tki.Button(self, text="Add", command=self.add_to_list)
self.edit = tki.Entry(self)
self.label = tki.Label(self, text="Hello Python", anchor='w')
self.master = master
self.place(anchor='nw', x=10, y=10, relwidth=1, relheight=1, bordermode='outside')
self.create_widgets()
def create_widgets(self):
self.label.place(x=10, y=10, width=100, height=20)
self.edit.place(x=10, y=30, width=250, height=24)
self.editb.place(x=270, y=24, width=100, height=30)
self.list.place(x=10, y=60, width=300, height=300)
def add_to_list(self):
self.list.insert(tki.END, self.edit.get())
root = tki.Tk()
root.minsize(500, 400)
ttl = root.title(