哔哩哔哩2023-07-02 21:05:11
最近到了假期,时间过得很快,但是效率又不高,于是我想到用Python制作一下日程管理工具,用于提醒我抓紧时间做好重要的事情。软件的图如下:
【资料图】
源码展如如下:
import tkinter as tk
from tkinter import messagebox
from datetime import datetime
import as tkFont
class ScheduleApp:
def __init__(self, master):
= master
("日程管理 by Gordon")
= (family="楷体", size=13)
# 创建标签、文本框和按钮
= (master, text="日程:",font=)
(row=0, column=0, padx=10, pady=10, sticky="e")
= (master, width=35)
(row=0, column=1, padx=10, pady=10, sticky="w",columnspan = 3)
_label = (master, text="时间:",font=)
_(row=1, column=0, padx=10, pady=10, sticky="e")
# 创建时间选择框
_var = (master)
_var = (master)
_var = (master)
_("08")
_("10")
_("00")
_option = (master, _var, *range(24))
_option = (master, _var, *range(60))
_option = (master, _var, *range(60))
_(row=1, column=1, padx=10, pady=10, sticky="w")
_(row=1, column=2, padx=10, pady=10, sticky="w")
_(row=1, column=3, padx=10, pady=10, sticky="w")
_label = (master, text="编辑:",font=)
_(row=2, column=0, padx=10, pady=10, sticky="e")
_btn = (master, text="添加", font=, command=_schedule)
_(row=2, column=1, ipadx=7,padx=10, pady=10, sticky="w")
_btn = (master, text="修改", font=, command=_schedule)
_(row=2, column=2, ipadx=7, padx=10, pady=10, sticky="w")
_btn = (master, text="删除", font=, command=_schedule)
_(row=2, column=3, ipadx=7, padx=10, pady=10, sticky="w")
# 创建日程列表框
_listbox = (master,font=,height=6,width=35)
_(row=3, column=0, columnspan=4, padx=10, pady=10)
# 添加示例数据
_list = [("制作每日一句", "07:50:00"), ("做Python题", "08:30:00"), ("马上关机睡觉", "12:24:40")]
for schedule, _ in _list:
_(, schedule+":"+_)
# 创建Label来显示时间
_label = (root, text="时间", font=("Arial", 16))
_(row=4, column=0, columnspan=4, padx=10, pady=1)
_time()
# 启动定时器
_schedule()
def update_time(self):
current_time = ().strftime("%H:%M:%S")
_(text=f"现在时间:{current_time}")
_(1000, _time) # 每隔一秒钟更新时间
def get_time(self):
schedule = ()
hour = _()
minute = _()
second = _()
time = f"{hour:0>2}:{minute:0>2}:{second:0>2}"
return schedule,time
def add_schedule(self):
schedule,time = _time()
if schedule and time:
_((schedule, time))
_(, schedule+":"+time)
(0, )
_("08")
_("00")
_("00")
else:
("警告", "请输入事件和时间!")
def modify_schedule(self):
selected_index = _()
old_schedule = _(selected_index)
if selected_index:
schedule,time = _time()
if schedule and time:
index = selected_index[0]
_list[index] = (schedule, time)
_(index)
_(index, schedule)
(0, )
_("08")
_("00")
_("00")
elif time and not schedule:
index = selected_index[0]
_list[index] = (old_schedule, time)
_(index)
_(index,old_(":")[0]+":"+time)
#_(index,old_(":")[0]+":"+time)
# print(index,_list[index])
else:
("警告", "请输入事件和时间!")
else:
("警告", "请选择要修改的事件!")
def delete_schedule(self):
# 删除日程
selected_index = _()
if selected_index:
index = selected_index[0]
_(index)
_(index)
(0, )
_("00")
_("00")
_("00")
else:
("警告", "请选择要删除的事件!")
def show_custom_info(self,message):
# 设置自定义的弹窗
top = ()
("提醒")
label = (top, text=message, font=("楷体", 18))
(padx=100, pady=60)
button = (top, text="OK", width=10, command=)
(pady=10)
def check_schedule(self):
now = ().strftime("%H:%M:%S")
for schedule, time in _list:
if now == time:
# 调用自定义消息框
_custom_info(f"提醒!{schedule}".split(":")[0]+f":{time}")
#("提醒", f"该事件已到时:{schedule}{time}")
(1000, _schedule) # 每隔一秒钟检查一次日程
# 创建主窗口
root = ()
# 实例化日程管理应用程序
app = ScheduleApp(root)
# 运行主循环
()
关键词: