- 创建 .idea 目录和相关配置文件,设置项目结构 - 添加多个课堂成果示例代码,涵盖不同主题和功能 - 创建和配置 .gitignore 文件,忽略特定文件和目录
39 lines
913 B
Python
39 lines
913 B
Python
'''挑战二:
|
||
|
||
运用学到的知识实现如图所示效果:
|
||
|
||
提示:
|
||
|
||
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()
|
||
|