TActivityIndicatorDemo 项目分析¶
项目信息¶
- 项目名称: TActivityIndicatorDemo
- 下载链接: TActivityIndicatorDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TActivityIndicatorDemo/
├── 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.Button2 = Button(self)
self.Button1 = Button(self)
self.ActivityIndicator1 = ActivityIndicator(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button2.OnClick = self.Button2Click
self.Button1.OnClick = self.Button1Click
# 可以设置ActivityIndicator的IndicatorType变换不同效果
# 创建一个 TActivityIndicator 控件
self.activity_indicator = ActivityIndicator(self)
self.activity_indicator.Parent = self # 设置父控件为窗体
self.activity_indicator.Left = 10 # 设置左边距离
self.activity_indicator.Top = 10 # 设置顶边距离
# 启动活动指示器
self.activity_indicator.Animate = True # 设置启用动画
# 添加一个按钮来停止活动指示器
self.stop_button = Button(self)
self.stop_button.Parent = self # 设置父控件为窗体
self.stop_button.Caption = '停止' # 设置标题
self.stop_button.SetBounds(10, 50, 100, 30) # 设置位置和宽高
# 为按钮点击事件绑定处理函数
self.stop_button.OnClick = self.stop_activity_indicator
# 定义停止活动指示器的函数
def stop_activity_indicator(self, Sender):
self.activity_indicator.Animate = False # 停止活动指示器
ShowMessage('活动指示器已停止') # 显示消息框
def Button1Click(self, Sender):
self.ActivityIndicator1.Animate = True
def Button2Click(self, Sender):
self.ActivityIndicator1.Animate = False
设计文件: Unit1.sct¶
def Button1Click(Sender):
def Button2Click(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 151
ClientWidth = 206
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object ActivityIndicator1: TActivityIndicator
Left = 8
Top = 88
IndicatorType = aitSectorRing
end
object Button1: TButton
Left = 48
Top = 88
Width = 75
Height = 25
Caption = #21551#29992
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 48
Top = 120
Width = 75
Height = 25
Caption = #20572#29992
TabOrder = 2
OnClick = Button2Click
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- ActivityIndicator1 (TActivityIndicator)
- Button1 (TButton)
- Button2 (TButton)
技术特点¶
- 包含4个GUI组件
- 定义3个事件处理
窗体属性¶
- caption: #20572#29992
- height: 151
- width: 206
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - stop_activity_indicator - Button1Click - Button2Click
事件绑定: - self.Button2.OnClick = self.Button2Click - self.Button1.OnClick = self.Button1Click - self.stop_button.OnClick = self.stop_activity_indicator