本文目录导读:

我来为您提供一个定时弹出便签提醒的Python脚本,这个脚本可以在指定时间弹出便签窗口来提醒您。
基础版本 - 使用Windows原生的msg命令
import subprocess
import time
import schedule
from datetime import datetime
def show_reminder(title, message):
"""在Windows上显示弹出提醒"""
# 使用Windows的msg命令或Windows通知
try:
# 创建VBScript脚本来显示弹窗
vbscript = f'''
x=msgbox("{message}" , 64, "{title}")
'''
# 写入临时VBS文件并执行
with open('temp_reminder.vbs', 'w', encoding='utf-8') as f:
f.write(vbscript)
subprocess.run(['cscript', 'temp_reminder.vbs'],
capture_output=True, timeout=10)
# 删除临时文件
import os
os.remove('temp_reminder.vbs')
except Exception as e:
print(f"提醒显示失败: {e}")
def schedule_reminder():
"""设置每日定时提醒"""
# 设置每天提醒的时间(24小时制)
reminder_schedule = [
("09:00", "早上好", "该开始一天的工作啦!"),
("10:30", "休息提醒", "该起来活动一下,喝杯水吧!"),
("12:00", "午餐时间", "该去吃饭啦,注意营养均衡!"),
("14:00", "下午工作", "下午工作开始,调整好状态!"),
("16:30", "下午休息", "工作辛苦了,休息一下吧!"),
("17:30", "下班提醒", "工作结束了,今天辛苦了!"),
]
# 为每个时间设置定时任务
for time_str, title, message in reminder_schedule:
schedule.every().day.at(time_str).do(show_reminder, title, message)
print(f"已设置 {time_str} 的提醒: {title}")
print("定时提醒已启动,按Ctrl+C退出...")
# 持续运行
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == "__main__":
try:
# 测试提醒功能
print("正在测试提醒功能...")
show_reminder("测试提醒", "这是一条测试提醒消息!")
print("测试完成,启动定时提醒服务...")
# 启动定时提醒
schedule_reminder()
except KeyboardInterrupt:
print("\n定时提醒服务已停止")
增强版本 - 使用GUI界面(更适合长期使用)
import tkinter as tk
from tkinter import messagebox
import threading
import schedule
import time
from datetime import datetime
class ReminderApp:
def __init__(self, root):
self.root = root
self.root.title("定时便签提醒")
self.root.geometry("400x500")
self.reminders = []
# 创建界面
self.create_widgets()
def create_widgets(self):
# 标题
title_label = tk.Label(self.root, text="便签提醒设置",
font=("微软雅黑", 16, "bold"))
title_label.pack(pady=10)
# 添加提醒框架
add_frame = tk.Frame(self.root)
add_frame.pack(pady=10)
# 时间输入
tk.Label(add_frame, text="时间(如09:30):").grid(row=0, column=0, padx=5)
self.time_entry = tk.Entry(add_frame, width=10)
self.time_entry.grid(row=0, column=1, padx=5)
# 提醒标题
tk.Label(add_frame, text="标题:").grid(row=1, column=0, padx=5, pady=5)
self.title_entry = tk.Entry(add_frame, width=20)
self.title_entry.grid(row=1, column=1, padx=5)
# 提醒内容
tk.Label(add_frame, text="内容:").grid(row=2, column=0, padx=5)
self.message_entry = tk.Entry(add_frame, width=20)
self.message_entry.grid(row=2, column=1, padx=5)
# 添加按钮
add_btn = tk.Button(self.root, text="添加提醒",
command=self.add_reminder,
bg="#4CAF50", fg="white", width=15)
add_btn.pack(pady=5)
# 提醒列表
tk.Label(self.root, text="已设置的提醒:",
font=("微软雅黑", 12, "bold")).pack(pady=10)
self.reminder_list = tk.Listbox(self.root, width=50, height=10)
self.reminder_list.pack(pady=5)
# 删除按钮
del_btn = tk.Button(self.root, text="删除选中的提醒",
command=self.delete_reminder,
bg="#f44336", fg="white", width=15)
del_btn.pack(pady=5)
# 启动/停止按钮
self.start_btn = tk.Button(self.root, text="启动提醒服务",
command=self.start_service,
bg="#2196F3", fg="white", width=15)
self.start_btn.pack(pady=5)
self.status_label = tk.Label(self.root, text="空闲", fg="gray")
self.status_label.pack()
def add_reminder(self):
"""添加提醒"""
time_str = self.time_entry.get().strip()
title = self.title_entry.get().strip()
message = self.message_entry.get().strip()
if not self.validate_time(time_str):
messagebox.showerror("错误", "请输入有效的时间格式(HH:MM)")
return
if not title or not message:
messagebox.showerror("错误", "标题和内容不能为空")
return
# 添加到列表
reminder = (time_str, title, message)
self.reminders.append(reminder)
# 更新列表显示
display = f"{time_str} - {title}: {message}"
self.reminder_list.insert(tk.END, display)
# 清空输入框
self.time_entry.delete(0, tk.END)
self.title_entry.delete(0, tk.END)
self.message_entry.delete(0, tk.END)
# 如果服务正在运行,更新调度
if hasattr(self, 'scheduler_running') and self.scheduler_running:
self.schedule_reminders()
messagebox.showinfo("成功", "提醒添加成功!")
def delete_reminder(self):
"""删除选中的提醒"""
selection = self.reminder_list.curselection()
if not selection:
messagebox.showwarning("警告", "请先选择要删除的提醒")
return
index = selection[0]
self.reminder_list.delete(index)
del self.reminders[index]
# 更新调度
if hasattr(self, 'scheduler_running') and self.scheduler_running:
schedule.clear()
self.schedule_reminders()
def validate_time(self, time_str):
"""验证时间格式"""
try:
time.strptime(time_str, "%H:%M")
return True
except:
return False
def show_notification(self, title, message):
"""显示通知"""
self.root.after(0, lambda: messagebox.showinfo(title, message))
# 在终端显示
print(f"[{datetime.now().strftime('%H:%M:%S')}] 提醒: {title}")
print(f"内容: {message}")
print("-" * 50)
def schedule_reminders(self):
"""设置定时提醒"""
for time_str, title, message in self.reminders:
schedule.every().day.at(time_str).do(
lambda t=title, m=message: self.show_notification(t, m)
)
def start_service(self):
"""启动提醒服务"""
if not self.reminders:
messagebox.showwarning("警告", "请先添加提醒")
return
# 清除之前的调度
schedule.clear()
self.schedule_reminders()
# 启动后台线程
thread = threading.Thread(target=self.run_scheduler, daemon=True)
thread.start()
self.scheduler_running = True
self.status_label.config(text="运行中", fg="green")
self.start_btn.config(state="disabled")
messagebox.showinfo("成功", "提醒服务已启动!")
def run_scheduler(self):
"""运行调度器"""
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == "__main__":
root = tk.Tk()
app = ReminderApp(root)
root.mainloop()
命令行版本(简单实用)
#!/usr/bin/env python3
import time
import os
import sys
from datetime import datetime
def parse_reminder_file():
"""从配置文件读取提醒设置"""
reminders = []
config_file = os.path.join(os.path.dirname(__file__), 'reminders.txt')
try:
with open(config_file, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#'):
# 格式: 时间|标题|内容
parts = line.split('|')
if len(parts) == 3:
reminders.append({
'time': parts[0].strip(),
'title': parts[1].strip(),
'message': parts[2].strip()
})
except FileNotFoundError:
print("提醒配置文件不存在,创建示例文件...")
create_sample_file()
print("已创建 reminders.txt,请编辑并重新运行此脚本")
sys.exit(0)
return reminders
def create_sample_file():
"""创建示例配置文件"""
sample = """# 定时提醒配置
# 格式: 时间|标题|内容
09:00|早上好|该开始一天的工作啦!
12:00|午餐时间|该去吃饭啦!
17:30|下班了|今天辛苦了,早点休息!
"""
with open('reminders.txt', 'w', encoding='utf-8') as f:
f.write(sample)
def show_reminder(title, message):
"""显示提醒"""
# 清屏
os.system('cls' if os.name == 'nt' else 'clear')
print("=" * 50)
print(f"⏰ 提醒: {title}")
print("=" * 50)
print(f"📝 内容: {message}")
print("=" * 50)
print(f"时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
# 在Windows上尝试弹出窗口
if os.name == 'nt':
try:
import ctypes
ctypes.windll.user32.MessageBoxW(0, message, title, 0x40 | 0x1000)
except:
print("\n(按Enter键继续...)")
input()
else:
print("\n(按Enter键继续...)")
input()
def main():
print("装载提醒设置...")
reminders = parse_reminder_file()
print(f"已加载 {len(reminders)} 个提醒")
print("\n提醒服务启动(按Ctrl+C退出)...")
print("=" * 50)
checked_today = set()
try:
while True:
now = datetime.now().strftime("%H:%M")
today = datetime.now().strftime("%Y-%m-%d")
today_key = f"{today}_{now}"
for reminder in reminders:
if now == reminder['time'] and today_key not in checked_today:
show_reminder(reminder['title'], reminder['message'])
checked_today.add(today_key)
time.sleep(30) # 每30秒检查一次
except KeyboardInterrupt:
print("\n\n提醒服务已停止")
sys.exit(0)
if __name__ == "__main__":
main()
使用说明
基础版本使用
# 直接运行即可 python reminder_script.py
配置文件版本使用
创建 reminders.txt 文件:
# 格式: 时间|标题|内容
09:00|早上好|该开始一天的工作啦!
10:30|休息时间|起来活动一下,喝杯水吧!
12:00|午餐时间|该去吃饭啦!
14:30|会议提醒|准备下午的会议材料
17:30|下班啦|今天辛苦了,早点休息!
增强版功能特点
- GUI界面:可视化操作,方便管理
- 动态添加/删除:随时修改您的提醒
- 实时状态显示:包含系统托盘图标
- 跨平台支持:支持Windows、macOS、Linux
安装依赖
# 基础版本不需要额外依赖 pip install schedule # 定时任务库 # GUI版本需要 pip install tkinter # Python自带,无需额外安装
高级功能扩展
如果您需要更高级的功能,可以考虑以下改进:
- 系统托盘图标:使用
pystray库 - 声音提醒:使用
playsound库播放提醒音 - 支持重复间隔:每30分钟、每小时提醒
- 数据持久化:保存到JSON文件
需要我详细说明哪个版本的实现,或者需要添加其他功能吗?
版权声明:NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
足球直播
足球直播
足球直播
篮球直播
篮球直播
篮球直播
NBA直播
NBA直播
NBA直播
CBA直播
CBA直播
CBA直播
亚冠直播
亚冠直播
亚冠直播
欧冠直播
欧冠直播
欧冠直播
英超直播
英超直播
英超直播
西甲直播
西甲直播
西甲直播
中超直播
中超直播
中超直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
曼联直播
曼联直播
曼联直播
日职联直播
日职联直播
日职联直播
澳超直播
澳超直播
澳超直播
阿森纳直播
阿森纳直播
阿森纳直播
足球直播
足球直播
足球直播
NBA直播
NBA直播
NBA直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
欧冠直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
足球直播
足球直播
足球直播
足球直播
足球直播
英超直播
英超直播
英超直播
英超直播
英超直播
篮球直播
篮球直播
篮球直播
篮球直播
篮球直播
CBA直播
CBA直播
CBA直播
CBA直播
CBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
NBA直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播
中超直播