Skip to content

TLabelDemo 项目分析

项目信息

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

文件结构

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

        # 创建一个 TLabel 实例
        self.label = Label(self)
        # 设置 TLabel 的属性
        self.label.Parent = self # 切记要写此句
        self.label.Caption = '代码方式创建TLabel'
        self.label.Left = 50   # 设置 TLabel 的左边距
        self.label.Top = 50    # 设置 TLabel 的上边距
        self.label.Width = 250 # 设置 TLabel 的宽度
        self.label.Height = 30 # 设置 TLabel 的高度
        self.label.Font.Size = 15  # 设置字体大小
        self.label.Font.Name = 'Arial'  # 设置字体名称
        self.label.Font.Color = clBlack # 设置字体颜色为黑色

设计文件: Unit1.sct


设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 205
  ClientWidth = 382
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object Label1: TLabel
    Left = 104
    Top = 152
    Width = 186
    Height = 37
    Caption = #30452#25509#25302#25918'TLabel'
    Color = clBtnFace
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clRed
    Font.Height = -27
    Font.Name = 'Segoe UI'
    Font.Style = []
    ParentColor = False
    ParentFont = False
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • Label1 (TLabel)

技术特点

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

窗体属性

  • caption: #30452#25509#25302#25918'TLabel
  • height: 205
  • width: 382

代码分析

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

定义的类: - Form1

定义的方法: - init