pythonV1V2/第28讲入会考验/课堂成果/课后作业2-珍惜时间.py
sairate 7df250638d chore: 添加项目基础结构和示例代码
- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
2025-07-05 09:36:00 +08:00

39 lines
913 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'''挑战二:
运用学到的知识实现如图所示效果:
提示:
1. 创建名言标签并配置在窗口中
2. 设置合适的窗口尺寸(或者尝试使用默认参数)'''
# 导入tkinter、time库
import tkinter as tk
import time
# 创建主窗口
root = tk.Tk()
root.title('大聪明的时钟')
root.geometry()
root.resizable(width=False,height=False)
# 创建时间标签
label = tk.Label(text='',font=('微软雅黑',60),fg='blue')
label.pack()
# 创建名言标签
label_text = tk.Label(text='一寸光阴一寸金,寸金难买寸光阴',font=('微软雅黑',30),fg='black')
label_text.pack()
# 定义更新时间的函数
def update_clock():
now = time.strftime('%H:%M:%S')
label.config(text=now)
root.after(1000,update_clock) # 每1秒1000毫秒调用一次update_clock函数
# 更新时间
update_clock()
# 运行主循环,等待用户交互
root.mainloop()