前言
这里是2025年的天影大侠,这东西是网课的时候做的,把钉钉放着,自己却在翻python文档,好神奇。
正文
分享用Python做的一个桌面时钟

代码如下,有注释,一目了然:
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
| import tkinter as tk from tkinter import messagebox import time
root = tk.Tk()
root.title('桌面时钟')
root.attributes("-alpha",0.95)
root.attributes('-topmost', True)
size = 40 width = size/4*25 height = size/4*8 color = "black" font = "微软雅黑"
screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2) root.geometry(size_geo) root.resizable(0,0)
def gettime(): dstr.set(time.strftime("%H:%M:%S")) root.after(1000, gettime)
dstr = tk.StringVar()
lb = tk.Label(root,textvariable=dstr,fg=color,font=(font,size))
lb.pack()
gettime()
root.mainloop()
|
拿着用用没问题