tkinter 电子时钟 实现时间日期 可实现透明 无标题栏

下面是一个使用Tkinter库实现的简单电子时钟,具有时间和日期显示功能,并设置为透明且无标题栏。

from tkinter import *
import time

root = Tk()
root.attributes("-fullscreen", True)
root.attributes("-transparent", True)
root.overrideredirect(True)

clock_label = Label(root, font=('calibri', 80, 'bold'), bg='black', fg='white')
clock_label.pack(anchor=CENTER, expand=YES)

def update_clock():
    current_time = time.strftime('%H:%M:%S')
    current_date = time.strftime('%A, %B %d, %Y')
    clock_label.config(text=current_time + '\n' + current_date)
    clock_label.after(1000, update_clock)

update_clock()
root.mainloop()

这个程序会创建一个全屏的窗口,并且将窗口设置为透明且无标题栏。然后,程序

以下是一个示例代码,用于创建一个简单的电子时钟,它显示当前的时间日期: ```python import tkinter as tk import time class Clock(tk.Frame): def __init__(self, parent=None, **kw): tk.Frame.__init__(self, parent, kw) self.time_label = tk.Label(self, font=("Helvetica", 48)) self.time_label.pack(side="top", fill="x", padx=50, pady=20) self.date_label = tk.Label(self, font=("Helvetica", 24)) self.date_label.pack(side="top", fill="x", padx=50, pady=10) self.tick() def tick(self): current_time = time.strftime("%H:%M:%S") current_date = time.strftime("%A, %B %d, %Y") self.time_label.config(text=current_time) self.date_label.config(text=current_date) self.time_label.after(200, self.tick) if __name__ == "__main__": root = tk.Tk() root.title("Clock") clock = Clock(root) clock.pack(side="top", fill="both", expand=True) root.mainloop() ``` 这个示例代码使用了 `tkinter` 来创建一个 `Clock` 类。这个类继承了 `Frame` 类,它包含了两个 `Label` 对象,分别用于显示时间日期。 在 `__init__` 方法中,我们创建了这两个标签,并设置它们的字体。然后,我们调用 `tick` 方法来更新这两个标签的文本,并使用 `after` 方法来定期调用 `tick` 方法,以更新时间日期的显示。 在 `__main__` 方法中,我们创建了一个 `Tk` 对象,并将其命名为 `Clock`。然后,我们创建了一个 `Clock` 对象,并将其放置在 `Tk` 对象中。最后,我们调用 `mainloop` 方法来启动图形界面的事件循环。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员SUMER

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值