TLabeledEditDemo 项目分析¶
项目信息¶
- 项目名称: TLabeledEditDemo
- 下载链接: TLabeledEditDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TLabeledEditDemo/
├── Extractor_Icon.ico
├── Project1.py
├── Project1.xml
├── Unit1.py
├── Unit1.pydfm
├── Unit1.sct
├── Unit1.sfm
主程序文件: Project1.py¶
from glcl import *
from Unit1 import *
def main():
Application.Initialize()
Application.Title = 'Project1'
Application.MainFormOnTaskbar = True
Application.Icon.LoadFromFile(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Extractor_Icon.ico"))
MainForm = Form1(Application)
MainForm.Show()
FreeConsole()
Application.Run()
MainForm.Free()
if __name__ == '__main__':
main()
单元文件: Unit1.py¶
import os
from glcl import *
class Form1(Form):
def __init__(self, owner):
self.Button1 = Button(self)
self.LabeledEdit1 = LabeledEdit(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button1.OnClick = self.Button1Click
# 创建 TLabeledEdit 组件
self.labeledEdit = LabeledEdit(self)
self.labeledEdit.Parent = self # 设置父组件为当前表单
self.labeledEdit.Top = 20 # 设置位置
self.labeledEdit.Left = 20 # 设置位置
self.labeledEdit.Width = 250 # 设置编辑框宽度
# 创建一个按钮用于显示输入的文本
self.showButton = Button(self)
self.showButton.Parent = self # 设置父组件为当前表单
self.showButton.Caption = 'Show Input' # 设置按钮文本
self.showButton.Top = 60 # 设置按钮位置
self.showButton.Left = 20 # 设置按钮位置
self.showButton.Width = 200 # 设置按钮宽度
self.showButton.OnClick = self.show_input # 绑定点击事件
def show_input(self, Sender):
# 按钮点击事件处理函数
input_text = self.labeledEdit.Text # 获取输入框中的文本
ShowMessage(f'You entered: {input_text}') # 显示输入的文本
def Button1Click(self, Sender):
ShowMessage(self.LabeledEdit1.Text)
设计文件: Unit1.sct¶
def Button1Click(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 194
ClientWidth = 305
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object LabeledEdit1: TLabeledEdit
Left = 8
Top = 152
Width = 121
Height = 28
EditLabel.Width = 87
EditLabel.Height = 20
EditLabel.Caption = 'LabeledEdit1'
PasswordChar = '*'
TabOrder = 0
Text = '123456'
end
object Button1: TButton
Left = 144
Top = 152
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- LabeledEdit1 (TLabeledEdit)
- Button1 (TButton)
技术特点¶
- 包含3个GUI组件
- 定义2个事件处理
窗体属性¶
- caption: Button1
- height: 194
- width: 305
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - show_input - Button1Click
事件绑定: - self.Button1.OnClick = self.Button1Click - self.showButton.OnClick = self.show_input # 绑定点击事件