试了一下用通义来编写一些代码,以下是一个在线时钟的样例,只要能运行python就可以使用。
以下是运行后的结果。
代码(复制可用)
import tkinter as tk
from time import strftimedef update_time():current_time = strftime("%H:%M:%S")current_date = strftime("%Y-%m-%d %A")time_label.config(text=current_time)date_label.config(text=current_date)root.after(1000, update_time)def toggle_fullscreen(event=None):"""切换全屏和正常屏幕状态"""state = not root.attributes('-fullscreen')root.attributes('-fullscreen', state)if not state: # 如果不是全屏,恢复原来的几何尺寸root.geometry('800x600') # 示例尺寸,可根据需要调整def close_window():"""关闭窗口"""root.destroy()root = tk.Tk()
root.title("实时时间与日期显示")# 绑定F11键切换全屏
root.bind("<F11>", toggle_fullscreen)
root.bind("<Escape>", toggle_fullscreen) # 允许使用Esc键退出全屏large_font = ("Arial", 150)
medium_font = ("Arial", 100)content_frame = tk.Frame(root)
content_frame.pack(expand=True, fill=tk.BOTH)time_label = tk.Label(content_frame, text="", font=large_font, fg="green", anchor="center")
time_label.pack(expand=True, fill=tk.BOTH, pady=(150, 20))date_label = tk.Label(content_frame, text="", font=medium_font, fg="blue", anchor="center")
date_label.pack(expand=True, fill=tk.BOTH)# 创建底部控制栏框架
control_frame = tk.Frame(root)
control_frame.pack(side=tk.BOTTOM, fill=tk.X)# 添加按钮
fullscreen_button = tk.Button(control_frame, text="切换全屏", command=toggle_fullscreen)
fullscreen_button.pack(side=tk.LEFT, padx=10)# 添加关闭按钮
close_button = tk.Button(control_frame, text="关闭", command=close_window)
close_button.pack(side=tk.RIGHT, padx=10)update_time()
root.mainloop()