Skip to content

TPageControlDemo 项目分析

项目信息

文件结构

TPageControlDemo/
├── 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.ComboBox5 = ComboBox(self)
        self.ComboBox4 = ComboBox(self)
        self.ComboBox3 = ComboBox(self)
        self.ComboBox2 = ComboBox(self)
        self.CheckBox5 = CheckBox(self)
        self.CheckBox4 = CheckBox(self)
        self.CheckBox3 = CheckBox(self)
        self.CheckBox2 = CheckBox(self)
        self.GroupBox1 = GroupBox(self)
        self.ComboBox1 = ComboBox(self)
        self.RadioButton1 = RadioButton(self)
        self.CheckBox1 = CheckBox(self)
        self.Button1 = Button(self)
        self.Edit1 = Edit(self)
        self.Label1 = Label(self)
        self.Panel1 = Panel(self)
        self.PageControl1 = PageControl(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button2.OnClick = self.Button2Click


    def Button2Click(self, Sender):
        self.PageControl1.TabIndex = 1

设计文件: Unit1.sct

def Button2Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 342
  ClientWidth = 501
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object PageControl1: TPageControl
    Left = 8
    Top = 8
    Width = 481
    Height = 289
    ActivePage = TabSheet1
    TabOrder = 0
    object TabSheet1: TTabSheet
      Caption = 'TabSheet1'
      object Panel1: TPanel
        Left = 12
        Top = 9
        Width = 449
        Height = 233
        Caption = 'Panel1'
        TabOrder = 0
        object Label1: TLabel
          Left = 40
          Top = 40
          Width = 44
          Height = 20
          Caption = 'Label1'
        end
        object Edit1: TEdit
          Left = 120
          Top = 40
          Width = 121
          Height = 28
          TabOrder = 0
          Text = 'Edit1'
        end
        object Button1: TButton
          Left = 280
          Top = 40
          Width = 75
          Height = 25
          Caption = 'Button1'
          TabOrder = 1
        end
      end
    end
    object TabSheet2: TTabSheet
      Caption = 'TabSheet2'
      object CheckBox1: TCheckBox
        Left = 44
        Top = 73
        Width = 97
        Height = 17
        Caption = 'CheckBox1'
        TabOrder = 0
      end
      object RadioButton1: TRadioButton
        Left = 204
        Top = 73
        Width = 113
        Height = 17
        Caption = 'RadioButton1'
        TabOrder = 1
      end
      object ComboBox1: TComboBox
        Left = 44
        Top = 153
        Width = 145
        Height = 28
        TabOrder = 2
        Text = 'ComboBox1'
      end
    end
    object TabSheet3: TTabSheet
      Caption = 'TabSheet3'
      object GroupBox1: TGroupBox
        Left = 20
        Top = 25
        Width = 409
        Height = 177
        Caption = 'GroupBox1'
        TabOrder = 0
        object CheckBox2: TCheckBox
          Left = 48
          Top = 56
          Width = 97
          Height = 17
          Caption = 'CheckBox2'
          TabOrder = 0
        end
        object CheckBox3: TCheckBox
          Left = 48
          Top = 120
          Width = 97
          Height = 17
          Caption = 'CheckBox3'
          TabOrder = 1
        end
        object CheckBox4: TCheckBox
          Left = 264
          Top = 56
          Width = 97
          Height = 17
          Caption = 'CheckBox4'
          TabOrder = 2
        end
        object CheckBox5: TCheckBox
          Left = 264
          Top = 120
          Width = 97
          Height = 17
          Caption = 'CheckBox5'
          TabOrder = 3
        end
      end
    end
    object TabSheet4: TTabSheet
      Caption = 'TabSheet4'
      object ComboBox2: TComboBox
        Left = 28
        Top = 25
        Width = 145
        Height = 28
        TabOrder = 0
        Text = 'ComboBox2'
      end
      object ComboBox3: TComboBox
        Left = 28
        Top = 81
        Width = 145
        Height = 28
        TabOrder = 1
        Text = 'ComboBox3'
      end
      object ComboBox4: TComboBox
        Left = 28
        Top = 137
        Width = 145
        Height = 28
        TabOrder = 2
        Text = 'ComboBox4'
      end
      object ComboBox5: TComboBox
        Left = 28
        Top = 193
        Width = 145
        Height = 28
        TabOrder = 3
        Text = 'ComboBox5'
      end
    end
  end
  object Button2: TButton
    Left = 414
    Top = 304
    Width = 75
    Height = 25
    Caption = 'Button2'
    TabOrder = 1
    OnClick = Button2Click
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • PageControl1 (TPageControl)
  • TabSheet1 (TTabSheet)
  • Panel1 (TPanel)
  • Label1 (TLabel)
  • Edit1 (TEdit)
  • Button1 (TButton)
  • TabSheet2 (TTabSheet)
  • CheckBox1 (TCheckBox)
  • RadioButton1 (TRadioButton)
  • ComboBox1 (TComboBox)
  • TabSheet3 (TTabSheet)
  • GroupBox1 (TGroupBox)
  • CheckBox2 (TCheckBox)
  • CheckBox3 (TCheckBox)
  • CheckBox4 (TCheckBox)
  • CheckBox5 (TCheckBox)
  • TabSheet4 (TTabSheet)
  • ComboBox2 (TComboBox)
  • ComboBox3 (TComboBox)
  • ComboBox4 (TComboBox)
  • ComboBox5 (TComboBox)
  • Button2 (TButton)

技术特点

  • 包含23个GUI组件
  • 定义1个事件处理

窗体属性

  • caption: Button2
  • height: 342
  • width: 501

代码分析

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

定义的类: - Form1

定义的方法: - init - Button2Click

事件绑定: - self.Button2.OnClick = self.Button2Click