zoukankan      html  css  js  c++  java
  • Python简易闹钟:全屏置顶弹窗提醒

    # 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。

  • 相关阅读:
    minikube dashboard 403 forbidden
    kubernetes 条件需求 修改内核和系统启动项
    kali 2020汉化 设置中文
    mac Memcached安装及基本命令-转载
    转载——Linux性能剖析工具—perf
    Django-migrations中的迁移版本和数据库中的迁移版本对不上怎么办?
    下载yum源中的rpm包
    server2008 安装mysql8.0
    好累啊!
    我与游戏
  • 原文地址:https://www.cnblogs.com/thisisajoke/p/13744449.html
Copyright © 2011-2022 走看看