Skip to content

TMaskEditDemo 项目分析

项目信息

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

文件结构

TMaskEditDemo/
├── 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.Button1 = Button(self)
        self.MaskEdit1 = MaskEdit(self)
        self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
        self.Button1.OnClick = self.Button1Click

        # 创建 TMaskEdit 控件
        self.mask_edit = MaskEdit(self)
        self.mask_edit.Parent = self  # 设置父控件
        self.mask_edit.Left = 50  # 设置控件的左侧位置
        self.mask_edit.Top = 50  # 设置控件的顶部位置
        self.mask_edit.EditMask = "!999-9999;1;_ "  # 设置输入掩码
        self.mask_edit.Width = 100  # 设置控件宽度

        # 创建按钮用于显示输入的值
        self.show_button = Button(self)
        self.show_button.Parent = self  # 设置父控件
        self.show_button.Caption = "显示输入"  # 设置按钮文本
        self.show_button.Left = 50  # 设置按钮的左侧位置
        self.show_button.Top = 100  # 设置按钮的顶部位置
        self.show_button.OnClick = self.on_show_button_click  # 设置点击事件处理函数

    def on_show_button_click(self, Sender):
        # 点击按钮时执行的操作
        user_input = self.mask_edit.Text  # 获取输入的文本
        ShowMessage(f"您输入的是: {user_input}")  # 弹出消息框显示输入内容

    def Button1Click(self, Sender):
        # 点击按钮时执行的操作
        user_input = self.MaskEdit1.Text  # 获取输入的文本
        ShowMessage(f"您输入的是: {user_input}")  # 弹出消息框显示输入内容

设计文件: Unit1.sct

def Button1Click(Sender): 

设计文件: Unit1.sfm

object Form1: TForm
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 260
  ClientWidth = 405
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -15
  Font.Name = 'Segoe UI'
  Font.Style = []
  TextHeight = 20
  object MaskEdit1: TMaskEdit
    Left = 56
    Top = 192
    Width = 119
    Height = 28
    EditMask = '\(999\)9000-0000;1;_'
    MaxLength = 14
    TabOrder = 0
    Text = '(   )    -    '
  end
  object Button1: TButton
    Left = 200
    Top = 195
    Width = 75
    Height = 25
    Caption = #26174#31034#36755#20837
    TabOrder = 1
    OnClick = Button1Click
  end
end

其他文件

  • Extractor_Icon.ico
  • Project1.xml

详细分析

功能概述

GUI组件演示

使用的组件

  • Form1 (TForm)
  • MaskEdit1 (TMaskEdit)
  • Button1 (TButton)

技术特点

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

窗体属性

  • caption: #26174#31034#36755#20837
  • height: 260
  • width: 405

代码分析

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

定义的类: - Form1

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

事件绑定: - self.Button1.OnClick = self.Button1Click - self.show_button.OnClick = self.on_show_button_click # 设置点击事件处理函数