-
Notifications
You must be signed in to change notification settings - Fork 13
/
win.py
44 lines (35 loc) · 1.27 KB
/
win.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 时钟
import tkinter as tk
import time
class Clock:
def __init__(self):
self.root = tk.Tk()
# 设置窗口无边框、背景透明
self.root.attributes("-fullscreen", True)
self.root.attributes("-alpha", 0.1) # 设置透明度
self.root.configure(background="black")
self.root.overrideredirect(True)
self.root.bind("<Escape>", lambda x: self.root.quit())
self.time_label = tk.Label(
self.root, text="", font=("Arial", 80), fg="white", bg="black"
)
self.time_label.place(relx=0.5, rely=0.4, anchor="center")
self.date_label = tk.Label(
self.root, text="", font=("Arial", 30), fg="white", bg="black"
)
self.date_label.place(relx=0.5, rely=0.6, anchor="center")
def get_time(self):
current_time = time.strftime("%H:%M:%S")
self.time_label.config(text=current_time)
self.root.after(1000, self.get_time)
def get_date(self):
current_date = time.strftime("%Y-%m-%d")
self.date_label.config(text=current_date)
self.root.after(60000, self.get_date)
def run(self):
self.get_time()
self.get_date()
self.root.mainloop()
if __name__ == "__main__":
clock = Clock()
clock.run()