Skip to content

TTabSetDemo 项目分析

项目信息

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

文件结构

TTabSetDemo/
├── 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.Notebook1 = Notebook(self)
        self.Button1 = Button(self)
        self.TabSet1 = TabSet(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button1.OnClick = self.Button1Click
        self.TabSet1.OnClick = self.TabSet1Click

    def TabSet1Click(self, Sender):
        # TabSet通常和Notebook搭配一起使用,Notebook为了向后兼容提供的,
        # 它是属于比较古老的控件,如今应该用PageControl
        self.Notebook1.PageIndex = self.TabSet1.TabIndex

    def Button1Click(self, Sender):
        # 设置显示风格
        self.TabSet1.Style = tsModernTabs

设计文件: Unit1.sct

def TabSet1Click(Sender): 
def Button1Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 381
  ClientWidth = 392
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object TabSet1: TTabSet
    Left = 24
    Top = 304
    Width = 345
    Height = 21
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -15
    Font.Name = 'Segoe UI'
    Font.Style = []
    Tabs.Strings = (
      #26631#31614#39029'1'
      #26631#31614#39029'2'
      #26631#31614#39029'3'
      #26631#31614#39029'4'
      #26631#31614#39029'5'
      #26631#31614#39029'6'
      #26631#31614#39029'7')
    TabIndex = 0
    OnClick = TabSet1Click
  end
  object Button1: TButton
    Left = 294
    Top = 344
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Notebook1: TNotebook
    Left = 24
    Top = 16
    Width = 345
    Height = 270
    PageIndex = 6
    TabOrder = 2
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page1'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page2'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page3'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page4'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page5'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page6'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
    object TPage
      Left = 0
      Top = 0
      Caption = 'Page7'
      ExplicitWidth = 0
      ExplicitHeight = 0
    end
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • TabSet1 (TTabSet)
  • Button1 (TButton)
  • Notebook1 (TNotebook)

技术特点

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

窗体属性

  • caption: Page7
  • height: 381
  • width: 392

代码分析

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

定义的类: - Form1

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

事件绑定: - self.Button1.OnClick = self.Button1Click - self.TabSet1.OnClick = self.TabSet1Click