TDateTimePickerDemo 项目分析¶
项目信息¶
- 项目名称: TDateTimePickerDemo
- 下载链接: TDateTimePickerDemo.rar
- 分析时间: 2026-03-05
文件结构¶
TDateTimePickerDemo/
├── 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.DateTimePicker1 = DateTimePicker(self)
self.LoadProps(os.path.join(os.path.dirname(os.path.abspath(__file__)), "Unit1.pydfm"))
self.Button1.OnClick = self.Button1Click
# 创建 TDateTimePicker 控件用于选择日期和时间
self.dateTimePicker = DateTimePicker(self)
self.dateTimePicker.SetBounds(50, 50, 200, 25) # 设置控件的位置和大小
self.dateTimePicker.Parent = self # 将控件设置为窗体的子控件
# 创建按钮用于获取选定的日期和时间
self.btnShowDateTime = Button(self)
self.btnShowDateTime.SetBounds(50, 100, 200, 30) # 设置按钮的位置和大小
self.btnShowDateTime.Caption = "显示选定的日期和时间" # 设置按钮文本
self.btnShowDateTime.OnClick = self.show_date_time # 绑定点击事件
self.btnShowDateTime.Parent = self # 将按钮设置为窗体的子控件
# 显示选定的日期和时间的方法
def show_date_time(self, Sender):
selected_date_time = self.dateTimePicker.DateTime # 获取选定的日期和时间
message = f"选定的日期和时间: {selected_date_time}" # 构建消息字符串
ShowMessage(message) # 显示消息框
def Button1Click(self, Sender):
selected_date_time = self.DateTimePicker1.DateTime # 获取选定的日期和时间
message = f"选定的日期和时间: {selected_date_time}" # 构建消息字符串
ShowMessage(message) # 显示消息框
设计文件: Unit1.sct¶
def Button1Click(Sender):
设计文件: 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 DateTimePicker1: TDateTimePicker
Left = 16
Top = 168
Width = 186
Height = 28
Date = 45566.00000000000000000
Time = 0.91807224536751170
TabOrder = 0
end
object Button1: TButton
Left = 216
Top = 168
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
其他文件¶
- Extractor_Icon.ico
- Project1.xml
详细分析¶
功能概述¶
图像处理组件演示
使用的组件¶
- Form1 (TForm)
- DateTimePicker1 (TDateTimePicker)
- Button1 (TButton)
技术特点¶
- 包含3个GUI组件
- 定义2个事件处理
窗体属性¶
- caption: Button1
- height: 205
- width: 382
代码分析¶
导入的模块: - import os - from glcl import *
定义的类: - Form1
定义的方法: - init - show_date_time - Button1Click
事件绑定: - self.Button1.OnClick = self.Button1Click - self.btnShowDateTime.OnClick = self.show_date_time # 绑定点击事件