首页 > 编程语言 > 详细

Python简易闹钟:全屏置顶弹窗提醒

时间:2020-09-28 15:01:29      阅读:79      评论:0      收藏:0      [点我收藏+]
# alarm.py
import time
import tkinter as tk


class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack(fill=tk.BOTH, expand=True)
        self.create_widgets()

    def create_widgets(self):
        self.info = tk.Label(self,
                              font="Fixedsys 36 bold",
                              text=r" 到饭点了! ")
        self.info.pack(fill=tk.X, pady=24)
    
        self.quit = tk.Button(self,
                              font="Fixedsys 36 bold",
                              text=r" 知道了,这就去吃饭! ",
                              bg="red",
                              fg=‘white‘,
                              command=self.master.destroy)
        self.quit.pack(fill=tk.X, pady=16)


def SetAlarm(time_str):
    set_hour = int(time_str.split(‘:‘)[0])
    set_mint = int(time_str.split(‘:‘)[1])
    window_poped = False
    while True:
        t = time.localtime()
        fmt = "%H %M"
        now = time.strftime(fmt, t)
        now = now.split(‘ ‘)
        hour = int(now[0])
        mint = int(now[1])
        
        if hour == set_hour and mint == set_mint:
            if not window_poped: # if not poped before then pop a window
                window_poped = True
                root = tk.Tk()
                root.wm_attributes(‘-topmost‘,1)
                root["background"] = "blue"
                root.attributes("-fullscreen", True)
                app = Application(master=root)
                app.mainloop()
            else: # window poped before then cancel the alarm this time
                continue
        else:
            window_poped = False
            
            
if __name__ == ‘__main__‘:
    SetAlarm(‘11:48‘)

更改main入口部分的时间“11:48”为你想要的时间即可。

提示:windows下,在CMD中端采用如下命令行可以实现后台运行本闹钟程序:

start /b python alarm.py

本程序要求系统安装Python3。

Python简易闹钟:全屏置顶弹窗提醒

原文:https://www.cnblogs.com/thisisajoke/p/13744449.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!