Skip to content

TGaugeDemo 项目分析

项目信息

  • 项目名称: TGaugeDemo
  • 下载链接: TGaugeDemo.rar
  • 分析时间: 2026-03-05

文件结构

TGaugeDemo/
├── 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 *
import time

class Form1(Form):

    def __init__(self, owner):
        self.Button1 = Button(self)
        self.Gauge1 = Gauge(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button1.OnClick = self.Button1Click

        # 创建一个TGauge实例,作为进度条
        self.gauge = Gauge(self)
        self.gauge.Parent = self        # 设置其父窗体为当前窗体
        self.gauge.Left = 50            # 设置进度条的左边位置
        self.gauge.Top = 50             # 设置进度条的顶边位置
        self.gauge.Width = 300          # 设置进度条的宽度
        self.gauge.Height = 30          # 设置进度条的高度
        self.gauge.MinValue = 0         # 进度条最小值
        self.gauge.MaxValue = 100       # 进度条最大值
        self.gauge.Progress = 0         # 进度初始值

        # 创建一个按钮,用于更新进度条
        self.button = Button(self)
        self.button.Parent = self        # 设置父控件为窗体
        self.button.Left = 150           # 设置按钮左边位置
        self.button.Top = 100            # 设置按钮顶边位置
        self.button.Caption = 'Start'    # 按钮标题
        self.button.OnClick = self.update_gauge  # 按钮点击事件

    # 按钮点击事件处理程序
    def update_gauge(self, Sender):
        # 模拟进度更新
        for i in range(self.gauge.MinValue, self.gauge.MaxValue + 1):
            self.gauge.Progress = i  # 更新进度条的值
            Application.ProcessMessages()  # 处理消息以避免界面卡死
            time.sleep(0.05)  # 模拟延迟,这里可以根据需要调整

    def Button1Click(self, Sender):
        for i in range(self.Gauge1.MinValue, self.Gauge1.MaxValue + 1):
            self.Gauge1.Progress = i  # 更新进度条的值
            Application.ProcessMessages()  # 处理消息以避免界面卡死
            time.sleep(0.05)  # 模拟延迟,这里可以根据需要调整

设计文件: Unit1.sct

def Button1Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 275
  ClientWidth = 382
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object Gauge1: TGauge
    Left = 16
    Top = 112
    Width = 356
    Height = 100
    Progress = 0
  end
  object Button1: TButton
    Left = 297
    Top = 216
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • Gauge1 (TGauge)
  • Button1 (TButton)

技术特点

  • 包含3个GUI组件
  • 定义2个事件处理

窗体属性

  • caption: Button1
  • height: 275
  • width: 382

代码分析

导入的模块: - import os - from glcl import * - import time

定义的类: - Form1

定义的方法: - init - update_gauge - Button1Click

事件绑定: - self.Button1.OnClick = self.Button1Click - self.button.OnClick = self.update_gauge # 按钮点击事件