TEditDemo 项目分析¶
项目信息¶
- 项目名称: TEditDemo
- 下载链接: TEditDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TEditDemo/
├── 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.Edit1 = Edit(self) # 通过拖放控件方式生成的代码,此处只是声明变量和类型,控件实例在Unit1.pydfm中
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
# 在LoadProps方法后面创建控件,该控件实例并未在Unit1.pydfm中定义
# 创建一个 Edit 控件
self.edit = Edit(self) # TEdit 控件的拥有者是当前的表单 (self)
self.edit.Parent = self # 将控件的父窗口设置为当前表单
self.edit.Left = 20 # 设置控件左边距
self.edit.Top = 100 # 设置控件上边距
self.edit.Width = 250 # 设置控件宽度
self.edit.Height = 20 # 设置控件高度
self.edit.Text = "123456789" # 设置控件的初始文本
self.edit.Color = clBlack # 设置颜色为黑色
self.edit.Font.Color = clGreen # 设置字体颜色为绿色
self.edit.MaxLength = 15 # 设置最大长度为15
self.edit.NumbersOnly = True # 设置仅接受数字
self.edit.PasswordChar = '*' # 设置密码字符,字符为#0时显示字符
self.edit.ReadOnly = False # 设置只读
设计文件: Unit1.sct¶
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 238
ClientWidth = 413
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object Edit1: TEdit
Left = 32
Top = 32
Width = 121
Height = 43
Color = clGreen
Font.Charset = DEFAULT_CHARSET
Font.Color = clYellow
Font.Height = -25
Font.Name = 'Segoe UI'
Font.Style = []
ParentFont = False
TabOrder = 0
Text = 'Edit1'
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- Edit1 (TEdit)
技术特点¶
- 包含2个GUI组件
- 定义0个事件处理
窗体属性¶
- caption: Form1
- height: 238
- width: 413
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init