python应用tkinter,20分钟后弹窗。
import tkinter as tk
import time
breakTime=2*60#休息时间,秒
showTime=20*60#弹出时间,秒,20分钟=20*60,必须大于breakTime
def close_popup(popup):
popup.destroy()
def show_popup():
popup = tk.Toplevel(root)
popup.wm_attributes("-topmost", True)
popup.state('zoomed') # 将窗口最大化
popup.overrideredirect(True)
popup_label = tk.Label(popup, text='现在是休息时间。', bg='black', fg='white', font=('Consolas', 12), width=30, height=2)
popup_label.pack()
root.after(1000*breakTime, close_popup, popup)#自己关闭程序
root.after(1000*showTime,show_popup)
current_time = time.strftime('%H:%M:%S')
#current_ts_ms = int(time.time() * 1000)
popup_label.config(text=f'{current_time},{breakTime}秒后锁屏结束。')
#popup_label.config(text=f'{current_ts_ms},{breakTime}秒后锁屏结束。')
root = tk.Tk()
root.title('Love You')
root.wm_attributes("-topmost", True)#最顶层
textLabel=tk.Label(root, text='人工智能break', bg='black', fg='white', font=('Consolas', 12), width=30, height=2)
textLabel.pack(side=tk.LEFT)
root.after(1000*showTime, show_popup)
root.withdraw()
root.mainloop()