File: now.pyw 1 #!/usr/bin/python 2 3 # The MIT License (MIT) 4 # 5 # Copyright (c) 2026 pacman64 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a copy 8 # of this software and associated documentation files (the "Software"), to deal 9 # in the Software without restriction, including without limitation the rights 10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 # copies of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be included in 15 # all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 # SOFTWARE. 24 25 26 info = ''' 27 A little GUI window with a live date/time clock updating every new minute, 28 and which you can also quit using the escape key. F1 shows this help message. 29 ''' 30 31 32 from datetime import datetime 33 from tkinter import Event, Label, Tk 34 from tkinter.messagebox import showinfo 35 36 37 def check_key(event: Event) -> None: 38 char = event.char 39 # quit app when escape key is pressed 40 if char != '' and ord(char) == 27: 41 window.quit() 42 # show help message when F1 is pressed 43 if event.keycode == 112: 44 showinfo('Now', info.strip().replace('\n', '')) 45 46 47 def tick() -> None: 48 now = datetime.now() 49 update(now) 50 window.after((60 - now.second) * 1000, tick) 51 52 53 def update(now: datetime) -> None: 54 window.title(now.strftime('%Y-%m-%d %H:%M')) 55 output.configure(text=now.strftime('%a %b %d\n%H:%M')) 56 57 58 window = Tk() 59 window.resizable(False, False) 60 window.bind('<KeyPress>', check_key) 61 output = Label(text='', font=('Lucida Console', 60)) 62 output.pack(padx=10, pady=5) 63 64 try: 65 tick() 66 window.mainloop() 67 except KeyboardInterrupt as _: 68 pass