下面是一个使用tkinter库实现的简单的电子时钟程序。该程序显示当前的时间和日期,并且可以设置为透明且无标题栏的窗口。
import tkinter as tk
import time
class Clock:
def __init__(self, root):
self.root = root
self.root.title('Clock')
self.root.overrideredirect(True) # 设置为无标题栏
self.root.attributes('-alpha', 0.7) # 设置为透明
self.label = tk.Label(self.root, font=('Helvetica', 100, 'bold'))
self.label.pack()
self.update()
def update(self):
current_time = time.strftime('%H:%M:%S')
current_date = time.strftime('%Y-%m-%d')
self.label.config(text=f'{current_time}\n{current_date}')
self.root.after(1000, self.update)
if __name__ == '__main__':
root = tk.Tk()
clock = Clock(root)
root.mainloop()
运行该程序将会显示一个透明且无标题栏的窗口,该窗口中会实时显示当前的时间和日期。可以根据需要调整窗口的透明度和字体大小等属性。