TGroupBoxDemo 项目分析¶
项目信息¶
- 项目名称: TGroupBoxDemo
- 下载链接: TGroupBoxDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TGroupBoxDemo/
├── 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.Edit1 = Edit(self)
self.Label1 = Label(self)
self.GroupBox1 = GroupBox(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button1.OnClick = self.Button1Click
# 创建 TGroupBox 控件
self.group_box = GroupBox(self)
self.group_box.Parent = self # 设置分组框的父控件为当前窗口
self.group_box.Caption = 'Settings' # 设置分组框标题
self.group_box.Left = 20 # 设置分组框左边距
self.group_box.Top = 30 # 设置分组框上边距
# 创建一个 TCheckBox 控件
self.check_box = CheckBox(self.group_box) # 将复选框放入分组框内
self.check_box.Parent = self.group_box # 设置复选框的父控件为分组框
self.check_box.Caption = 'Enable Feature' # 设置复选框标题
self.check_box.Left = 20 # 设置复选框左边距
self.check_box.Top = 30 # 设置复选框上边距
# 创建一个 TButton 控件
self.button = Button(self.group_box) # 将按钮放入分组框内
self.button.Parent = self.group_box # 设置按钮的父控件为分组框
self.button.Caption = 'Submit' # 设置按钮标题
self.button.Left = 20 # 设置按钮左边距
self.button.Top = 60 # 设置按钮上边距
self.button.OnClick = self.on_button_click # 绑定按钮点击事件
def on_button_click(self, sender):
# 处理按钮点击事件
if self.check_box.Checked:
ShowMessage('Feature Enabled') # 显示消息框
else:
ShowMessage('Feature Disabled') # 显示消息框
def Button1Click(self, Sender):
self.Label1.Caption = 'TGroupBox'
self.Edit1.Text = 'Hello World'
设计文件: Unit1.sct¶
def Button1Click(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 354
ClientWidth = 394
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object GroupBox1: TGroupBox
Left = 8
Top = 184
Width = 289
Height = 153
Caption = #20998#32452#26694
TabOrder = 0
object Label1: TLabel
Left = 24
Top = 32
Width = 44
Height = 20
Caption = 'Label1'
end
object Edit1: TEdit
Left = 24
Top = 72
Width = 121
Height = 28
TabOrder = 0
Text = 'Edit1'
end
object Button1: TButton
Left = 198
Top = 75
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- GroupBox1 (TGroupBox)
- Label1 (TLabel)
- Edit1 (TEdit)
- Button1 (TButton)
技术特点¶
- 包含5个GUI组件
- 定义2个事件处理
窗体属性¶
- caption: Button1
- height: 354
- width: 394
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - on_button_click - Button1Click
事件绑定: - self.Button1.OnClick = self.Button1Click - self.button.OnClick = self.on_button_click # 绑定按钮点击事件