#!/usr/bin/python3
import tkinter as tk
from tkinter import messagebox,Label,StringVar
import time
from schedule import repeat, every, run_pending
@repeat(every(10).seconds, sec=3, msg = "起来喝杯咖啡!")
@repeat(every().day.at("8:50"), sec=6, msg = "今天打卡了吗?")
@repeat(every().day.at("16:50"), sec=6, msg = "快到下班时间!")
@repeat(every(1).hours, sec=3, msg = "您需要休息了!")
def show_message(sec=3, msg = ""):
root = tk.Tk()
root.title("系统提示")
root.resizable(False,False)
root.configure(background='lightcyan')
root.attributes("-topmost",1)
w, h = 200, 200
root.geometry( "%dx%d+%d+%d" %(w,h,(root.winfo_screenwidth()-w)/1-80,(root.winfo_screenheight()-h)/1-30) )
timerStr = StringVar()
timerStr.set(time.strftime('%H:%M:%S', time.localtime(time.time())))
Label(root, textvariable=timerStr, bg='darkturquoise', font=('Microsoft YaHei', 20), fg='white')\
.place(x=0, y=0, width=200, height=30)
Label(root, text=msg, bg='lightcyan', font=('OPPOSans R', 16))\
.place(x=10, y=100, width=200, height=30)
root.after(1000*sec, root.destroy )
root.mainloop()
if __name__ == "__main__":
print("task started !\n")
while True:
run_pending()
time.sleep(1)
报错如下:
--------------------------------------------------------------------------- ScheduleValueError Traceback (most recent call last) Cell In[14], line 10 4 import time 5 from schedule import repeat, every, run_pending 9 @repeat(every(10).seconds, sec=3, msg = "起来喝杯咖啡!") ---> 10 @repeat(every().day.at("8:50"), sec=6, msg = "今天打卡了吗?") 11 @repeat(every().day.at("16:50"), sec=6, msg = "快到下班时间!") 12 @repeat(every(1).hours, sec=3, msg = "您需要休息了!") 13 def show_message(sec=3, msg = ""): 14 root = tk.Tk() 15 root.title("系统提示") File /opt/conda/lib/python3.11/site-packages/schedule/__init__.py:516, in Job.at(self, time_str, tz) 514 if self.unit == "days" or self.start_day: 515 if not re.match(r"^[0-2]\d:[0-5]\d(:[0-5]\d)?$", time_str): --> 516 raise ScheduleValueError( 517 "Invalid time format for a daily job (valid format is HH:MM(:SS)?)" 518 ) 519 if self.unit == "hours": 520 if not re.match(r"^([0-5]\d)?:[0-5]\d$", time_str): ScheduleValueError: Invalid time format for a daily job (valid format is HH:MM(:SS)?)