mysql5资源共享

 找回密码
 立即注册
查看: 27|回复: 0

[MS-SQL Server] 【基础】时钟代码

[复制链接]

1

主题

1

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2019-7-12 11:59:47 | 显示全部楼层 |阅读模式
本人新手小白,想求各位大神解释一下这个时钟的代码,有些地方看不懂看不懂,蟹蟹



fromturtleimport*
fromdatetimeimport*

defSkip(step):
penup()
forward(step)
pendown()

defmkHand(name,length):
#注册Turtle形状,建立表针Turtle
reset()#清空当前窗口,并重置位置等信息为默认值
Skip(-length*0.1)
begin_poly()
forward(length*1.1)
end_poly()
handForm=get_poly()
register_shape(name,handForm)

defInit():
globalsecHand,minHand,hurHand,printer
mode("logo")#重置Turtle指向北
#建立三个表针Turtle并初始化
mkHand("secHand",135)
mkHand("minHand",110)
mkHand("hurHand",90)
secHand=Turtle()
secHand.shape("secHand")
minHand=Turtle()
minHand.shape("minHand")
hurHand=Turtle()
hurHand.shape("hurHand")
forhandinsecHand,minHand,hurHand:
hand.shapesize(1,1,3)
hand.speed(0)
#建立输出文字Turtle
printer=Turtle()
printer.hideturtle()
printer.penup()

defSetupClock(radius):
#建立表的外框
reset()
pensize(7)
foriinrange(60):
Skip(radius)
ifi%5==0:
forward(20)
Skip(-radius-20)
else:
dot(5)
Skip(-radius)
right(6)

defWeek(t):
week=["星期一","星期二","星期三",
"星期四","星期五","星期六","星期日"]
returnweek[t.weekday()]

defDate(t):
y=t.year
m=t.month
d=t.day
return"%s%d%d"%(y,m,d)

defTick():
#绘制表针的动态显示
t=datetime.today()
second=t.second+t.microsecond*0.000001
minute=t.minute+second/60.0
hour=t.hour+minute/60.0
secHand.setheading(6*second)#设置朝向,每秒转动6度
minHand.setheading(6*minute)
hurHand.setheading(30*hour)

tracer(False)#不显示绘制的过程,直接显示绘制结果
printer.forward(65)
printer.write(Week(t),align="center",
font=("Courier",14,"bold"))
printer.back(130)
printer.write(Date(t),align="center",
font=("Courier",14,"bold"))
printer.back(50)
printer.write("i_chaoren",align="center",
font=("Courier",14,"bold"))
printer.home()
tracer(True)

ontimer(Tick,1000)#1000ms后继续调用tick

defmain():
tracer(False)#使多个绘制对象同时显示
Init()
SetupClock(160)
tracer(True)
Tick()
mainloop()

if__name__=="__main__":
main()
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|mysql5.com Inc. ( 闽ICP备17002856号-1 )

GMT+8, 2019-10-23 01:25 , Processed in 0.043404 second(s), 18 queries .

Powered by MySQL5.com X3.4

© 2003-2019 MySQL5.com.

快速回复 返回顶部 返回列表