1.初始设置 |
from datetime import*#导入相关库 from turtle import* from time import sleep setup(675,675)#设置窗口大小 hideturtle()#隐藏海龟 mode("logo")#设置模式 |
2.读取时间 |
while(True):#重复执行 hideturtle()#隐藏海龟 curr=datetime.now()#读取时间 year=curr.year month=curr.month day=curr.day hour=curr.hour minute=curr.minute second=curr.second |
3.数据加工 |
if month<10:#不满10,在前面加个0 showmonth="0"+str(month) else: showmonth=str(month) if day<10: showday="0"+str(day) else: showday=str(day) if hour<10: showhour="0"+str(hour) else: showhour=str(hour) if minute<10: showminute="0"+str(minute) else: showminute=str(minute) if second<10: showsecond="0"+str(second) else: showsecond=str(second) weekday=(curr.weekday())#读取星期 weekday+=1#(实际是0~6,要改成1~7) |
4.显示时间 |
show="(星期"+str(weekday)+")"+str(year)+"年"+showmonth+"月"+showday+"日"+showhour+"时"+showminute+"分"+showsecond+"秒"#设时间 write(show,font=("Times New Roman",15))#写时间(同时设置字体) sleep(.9512)#打印需要一点点时间,所以等待时间要比1秒少一点点 |
5.完整代码 |
from datetime import*#导入相关库 from turtle import* from time import sleep setup(675,675)#设置窗口大小 hideturtle()#隐藏海龟 mode("logo")#设置模式 while(True):#重复执行 hideturtle()#隐藏海龟 curr=datetime.now()#读取时间 year=curr.year month=curr.month day=curr.day hour=curr.hour minute=curr.minute second=curr.second if month<10:#不满10,在前面加个0 showmonth="0"+str(month) else: showmonth=str(month) if day<10: showday="0"+str(day) else: showday=str(day) if hour<10: showhour="0"+str(hour) else: showhour=str(hour) if minute<10: showminute="0"+str(minute) else: showminute=str(minute) if second<10: showsecond="0"+str(second) else: showsecond=str(second) weekday=(curr.weekday())#读取星期 weekday+=1#(实际是0~6,要改成1~7) show="(星期"+str(weekday)+")"+str(year)+"年"+showmonth+"月"+showday+"日"+showhour+"时"+showminute+"分"+showsecond+"秒"#设时间 write(show,font=("Times New Roman",15))#写时间(同时设置字体) sleep(.9512)#打印需要一点点时间,所以等待时间要比1秒少一点点 |
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)