Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

用python设计一个窗口,名字为时钟,窗口背景为一张图片,中间显示“现在是北京时间:具体时间”

  1. User

    用python设计一个窗口,名字为时钟,窗口背景为一张图片,中间显示“现在是北京时间:具体时间”

  2. Assistant

    这是一个简单的用Python tkinter库设计窗口的程序,你可以根据你的实际需求进行修改:

    import time
    import tkinter as tk
    
    # 创建窗口
    window = tk.Tk()
    window.title("时钟")
    window.geometry("500x500")
    
    # 加载背景图片
    bg_image = tk.PhotoImage(file="your_background_image.png")
    background_label = tk.Label(window, image=bg_image)
    background_label.place(x=0, y=0, relwidth=1, relheight=1)
    
    # 显示时间的Label
    time_label = tk.Label(window, font=("Courier", 50), bg="white", fg="black")
    time_label.pack(pady=200)
    
    # 更新时间函数
    def update_time():
        now = time.strftime("现在是北京时间:%Y-%m-%d %H:%M:%S", time.localtime())
        time_label.config(text=now)
        window.after(1000, update_time)
    
    # 开始更新时间
    update_time()
    
    # 进入主循环
    window.mainloop()
    

    这个程序会在窗口中显示一张背景图片,并在图片中央以50号Courier字体和黑底白字显示当前时间。程序会每秒钟更新时间。请将图片路径改为你想要的背景图片的路径。