todo_win = None
todo_file = "todo.txt"
def show_todo(event=None):
global todo_win
if todo_win is not None and tk.Toplevel.winfo_exists(todo_win):
todo_win.destroy()
todo_win = None
return
todo_win = tk.Toplevel(root)
todo_win.title("待办事项")
todo_win.geometry("400x300")
todo_win.attributes('-topmost', True)
todo_win.grab_set()
todo_win.focus_set()
todo_win.configure(bg='#34495E')
label = tk.Label(todo_win, text="待办事项", font=("Microsoft YaHei UI", 20, "bold"), fg="#3498DB", bg='#34495E')
label.pack(pady=10)
text = tk.Text(todo_win, font=("Microsoft YaHei UI", 14), bg="#ECF0F1", height=10)
text.pack(padx=20, pady=10, fill='both', expand=True)
try:
with open(todo_file, 'r', encoding='utf-8') as f:
content = f.read()
text.insert('1.0', content)
except Exception: pass
def save_content(event=None):
try:
with open(todo_file, 'w', encoding='utf-8') as f:
f.write(text.get('1.0', 'end-1c'))
except Exception: pass
def close_todo(event=None):
global todo_win
save_content()
if todo_win is not None:
todo_win.destroy()
todo_win = None
btn = tk.Button(todo_win, text="关闭", font=("Microsoft YaHei UI", 12), command=close_todo)
btn.pack(pady=10)
todo_win.protocol("WM_DELETE_WINDOW", close_todo)
todo_win.bind('<Escape>', close_todo)
text.bind('<Control-s>', save_content)
text.bind('<KeyRelease>', lambda e: save_content())
import tkinter as tk
import time
import math
def exit_screensaver(event=None):
root.quit()
def draw_clock_face():
clock_canvas.delete("all")
current_time = time.localtime()
hours = current_time.tm_hour % 12
minutes = current_time.tm_min
seconds = current_time.tm_sec
clock_canvas.create_oval(10, 10, 390, 390, width=2, outline="#ECF0F1")
for i in range(12):
angle = i * math.pi/6 - math.pi/2
start_x = 200 + 190 * math.cos(angle)
start_y = 200 + 190 * math.sin(angle)
end_x = 200 + 180 * math.cos(angle)
end_y = 200 + 180 * math.sin(angle)
width = 3 if i % 3 == 0 else 1
clock_canvas.create_line(start_x, start_y, end_x, end_y, fill="#ECF0F1", width=width)
num = 12 if i == 0 else i
text_x = 200 + 155 * math.cos(angle)
text_y = 200 + 155 * math.sin(angle)
clock_canvas.create_text(text_x, text_y, text=str(num), font=("Microsoft YaHei UI", 20, "bold"), fill="#ECF0F1")
hour_angle = (hours + minutes/60) * math.pi/6 - math.pi/2
hour_x = 200 + 100 * math.cos(hour_angle)
hour_y = 200 + 100 * math.sin(hour_angle)
clock_canvas.create_line(200, 200, hour_x, hour_y, fill="#3498DB", width=8)
min_angle = minutes * math.pi/30 - math.pi/2
min_x = 200 + 140 * math.cos(min_angle)
min_y = 200 + 140 * math.sin(min_angle)
clock_canvas.create_line(200, 200, min_x, min_y, fill="#ECF0F1", width=6)
sec_angle = seconds * math.pi/30 - math.pi/2
sec_x = 200 + 160 * math.cos(sec_angle)
sec_y = 200 + 160 * math.sin(sec_angle)
clock_canvas.create_line(200, 200, sec_x, sec_y, fill="#FFA500", width=2)
clock_canvas.create_oval(195, 195, 205, 205, fill="#3498DB")
root.after(1000, draw_clock_face)
def update_clock():
current_time = time.localtime()
year = current_time.tm_year
month = current_time.tm_mon
day = current_time.tm_mday
weekday = current_time.tm_wday
hours = current_time.tm_hour
minutes = current_time.tm_min
seconds = current_time.tm_sec
date_str = f"{year}年{month:02d}月{day:02d}日"
weekday_str = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"][weekday]
time_str = f"{hours:02d}:{minutes:02d}:"
seconds_str = f"{seconds:02d}"
date_label.config(text=date_str)
weekday_label.config(text=weekday_str)
time_label.config(text=time_str)
seconds_label.config(text=seconds_str)
root.after(1000, update_clock)
todo_win = None
todo_file = "todo.txt"
def show_todo(event=None):
global todo_win
if todo_win is not None and tk.Toplevel.winfo_exists(todo_win):
todo_win.destroy()
todo_win = None
return
todo_win = tk.Toplevel(root)
todo_win.title("待办事项")
todo_win.geometry("400x300")
todo_win.attributes('-topmost', True)
todo_win.grab_set()
todo_win.focus_set()
todo_win.configure(bg='#34495E')
label = tk.Label(todo_win, text="待办事项", font=("Microsoft YaHei UI", 20, "bold"), fg="#3498DB", bg='#34495E')
label.pack(pady=10)
text = tk.Text(todo_win, font=("Microsoft YaHei UI", 14), bg="#ECF0F1", height=10)
text.pack(padx=20, pady=10, fill='both', expand=True)
try:
with open(todo_file, 'r', encoding='utf-8') as f:
content = f.read()
text.insert('1.0', content)
except Exception: pass
def save_content(event=None):
try:
with open(todo_file, 'w', encoding='utf-8') as f:
f.write(text.get('1.0', 'end-1c'))
except Exception: pass
def close_todo(event=None):
global todo_win
save_content()
if todo_win is not None:
todo_win.destroy()
todo_win = None
def main():
global root, clock_canvas, date_label, weekday_label, time_label, seconds_label
root = tk.Tk()
root.title("桌面时钟屏保")
root.attributes('-fullscreen', True)
root.attributes('-topmost', True)
root.config(cursor="none")
root.bind('<Key>', exit_screensaver)
root.bind('<Motion>', exit_screensaver)
root.bind('<Button>', exit_screensaver)
root.bind('<Escape>', exit_screensaver)
root.bind('<space>', show_todo)
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
main_frame = tk.Frame(root)
main_frame.pack(expand=True, fill='both')
main_frame.configure(bg='#2C3E50')
content_frame = tk.Frame(main_frame, bg='#2C3E50', padx=20, pady=20)
content_frame.pack(expand=True)
analog_frame = tk.Frame(content_frame, bg='#34495E', padx=30, pady=30)
analog_frame.pack(side='left', padx=20, fill='both', expand=True)
clock_canvas = tk.Canvas(analog_frame, width=400, height=400, bg='#34495E', highlightthickness=0)
clock_canvas.pack(expand=True)
clock_frame = tk.Frame(content_frame, bg='#34495E', padx=30, pady=30)
clock_frame.pack(side='right', padx=20, fill='both', expand=True)
date_label = tk.Label(clock_frame, font=("Microsoft YaHei UI", 36, "bold"), fg="#ECF0F1", bg="#34495E")
date_label.pack(pady=10)
weekday_label = tk.Label(clock_frame, font=("Microsoft YaHei UI", 28), fg="#BDC3C7", bg="#34495E")
weekday_label.pack(pady=10)
time_frame = tk.Frame(clock_frame, bg='#34495E')
time_frame.pack(pady=10)
time_label = tk.Label(time_frame, font=("Microsoft YaHei UI", 80, "bold"), fg="#3498DB", bg='#34495E')
time_label.pack(side='left')
seconds_label = tk.Label(time_frame, font=("Microsoft YaHei UI", 80, "bold"), fg="#FFA500", bg='#34495E')
seconds_label.pack(side='left')
footer_label = tk.Label(main_frame, text="按空格键查看待办事项 | ESC 键退出并保存", font=("Microsoft YaHei UI", 14), fg="#95A5A6", bg='#2C3E50')
footer_label.pack(side='bottom', pady=15)
btn = tk.Button(todo_win, text="关闭", font=("Microsoft YaHei UI", 12), command=close_todo) if 'todo_win' in globals() else None
update_clock()
draw_clock_face()
root.mainloop()
if __name__ == "__main__":
main()