本地创建任务,定时提醒。
首先设置一下提示音
import winsound
sound = lambda: winsound.MessageBeep(winsound.MB_ICONASTERISK) # 播放提示音
#代码太长了 缩短一下
sound() # 播放声音
然后做弹窗
from tkinter import *
def tc(time, txt): # 弹窗
root = Tk()
root.wm_attributes('-topmost', 1) # 置顶显示
root.title(time)
root.geometry("250x130-0-35") # 宽度 250,高度 130;距屏幕右边 0,距屏幕下边35
label01 = Label(root, text=txt,font=("华文行楷",18,"italic"))#华文行楷 字号20 斜体
label01.pack(padx=10, pady=40) # 调整文字位置
sound()#提示音
root.mainloop()
最后创建一下任务和时间就行了,为了便于修改,直接使用记事本创建任务了
中间是任务所用时间 右边是任务
最后成品 画面比较简陋 自己用也没必要多好看
import winsound
import time
from tkinter import *
sound = lambda: winsound.MessageBeep(winsound.MB_ICONASTERISK) # 播放提示音
sound() # 播放声音
txt_lines = open(r"D:\1ab\Python\python笔记\123.txt", "r", encoding="utf-8").readlines()
def tc(time, txt): # 弹窗
root = Tk()
root.wm_attributes('-topmost', 1) # 置顶显示
root.title(time)
root.geometry("250x130-0-35") # 宽度 500,高度 400;距屏幕左边 100,距屏幕上边200
label01 = Label(root, text=txt, font=("gb2312", 12))
label01.pack(padx=10, pady=40) # 调整文字位置
sound() # 提示音
root.mainloop()
for i in txt_lines:
a = i.split()
a[0] = a[0] + ":00"
while True:
time_set = a[0]
time_now = time.strftime("%H:%M:%S", time.localtime()) # 刷新时间
if time_now == time_set:
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
tc(time_now, a[2] + "\n" + a[1] + " 分钟") # 弹窗提示
if i == txt_lines[-1]:#如果是最后一个任务,则直接退出循环
break
time.sleep(eval(a[1]) * 60 - 60) # 等待 阻塞进程 避免长时间循环,占用资源
break