Skip to content

TShapeDemo 项目分析

项目信息

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

文件结构

TShapeDemo/
├── 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.Shape1 = Shape(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))

        # 创建一个 TShape 对象
        self.shape = Shape(self)
        # 设置形状的位置和大小
        self.shape.Left = 50      # 距离窗体左边的距离
        self.shape.Top = 50       # 距离窗体顶部的距离
        self.shape.Width = 100     # 形状的宽度
        self.shape.Height = 100    # 形状的高度
        self.shape.Brush.Color = clBlue  # 设置填充颜色为蓝色
        self.shape.Pen.Color = clBlack   # 设置边框颜色为黑色
        self.shape.Pen.Width = 2          # 设置边框宽度

        # 将形状添加到窗体中
        self.shape.Parent = self

设计文件: Unit1.sct


设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 275
  ClientWidth = 274
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object Shape1: TShape
    Left = 112
    Top = 192
    Width = 65
    Height = 65
    Brush.Color = clLime
    Brush.Style = bsDiagCross
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • Shape1 (TShape)

技术特点

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

窗体属性

  • caption: Form1
  • height: 275
  • width: 274

代码分析

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

定义的类: - Form1

定义的方法: - init