TCalendarDemo 项目分析¶
项目信息¶
- 项目名称: TCalendarDemo
- 下载链接: TCalendarDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TCalendarDemo/
├── 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.Calendar1 = Calendar(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Calendar1.OnDblClick = self.Calendar1DblClick
# 创建一个TCalendar控件,用于选择日期
self.calendar = Calendar(self)
self.calendar.Parent = self # 设置父控件为当前窗体
self.calendar.Align = alTop # 设置控件对齐方式为顶部
self.calendar.OnChange = self.calendar_onchange # 设置改变事件
# 创建一个标签用于显示所选日期
self.label = Label(self)
self.label.Parent = self # 设置父控件为当前窗体
self.label.Left = 10 # 设置标签的左侧位置
self.label.Top = 300 # 设置顶部距离
self.label.Top = self.calendar.Height + 10 # 设置标签的顶部位置,位于日历下方
self.label.Caption = 'Selected Date: ' # 标签标题
def calendar_onchange(self, Sender):
self.label.Caption = self.calendar.CalendarDate
def Calendar1DblClick(self, Sender):
ShowMessage(self.Calendar1.CalendarDate)
设计文件: Unit1.sct¶
def Calendar1DblClick(Sender):
设计文件: Unit1.sfm¶
object Form1: TForm
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 328
ClientWidth = 567
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -15
Font.Name = 'Segoe UI'
Font.Style = []
TextHeight = 20
object Calendar1: TCalendar
Left = 192
Top = 168
Width = 352
Height = 144
StartOfWeek = 0
TabOrder = 0
OnDblClick = Calendar1DblClick
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
GUI组件演示
使用的组件¶
- Form1 (TForm)
- Calendar1 (TCalendar)
技术特点¶
- 包含2个GUI组件
- 定义1个事件处理
窗体属性¶
- caption: Form1
- height: 328
- width: 567
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - calendar_onchange - Calendar1DblClick
事件绑定: - self.calendar.OnChange = self.calendar_onchange # 设置改变事件