马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 1406598279 于 2021-3-14 19:47 编辑 一个时钟程序:
源代码:
#导入
import turtle as t
import datetime as ti
import time
#画出背景
game = t.Screen()
game.bgcolor('black')
game.setup(600,600)
game.tracer(0)
#画圈
pen = t.Turtle()
pen.ht()
pen.speed(0)
pen.up()
pen.pensize(5)
def draw_clock(h,m,s):
pen.clear()
pen.up()
pen.color('yellow')
pen.goto(0,-210)
pen.down()
pen.seth(0)
pen.circle(210)
#画刻度
pen.up()
pen.goto(0,0)
pen.seth(90)
for i in range(12):
pen.fd(190)
pen.down()
pen.fd(20)
pen.up()
pen.goto(0,0)
pen.rt(30)
#画时针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(h/12*360)
pen.color('white')
pen.fd(80)
#画分针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(m/60*360)
pen.color('red')
pen.fd(120)
#画秒针
pen.up()
pen.goto(0,0)
pen.down()
pen.seth(90)
pen.rt(s/60*360)
pen.color('blue')
pen.fd(160)
pen.up()
pen.goto(-200,250)
pen.color("red")
font = ('Arial',20,'bold')
hello = "今天是{}年{}月{}日".format(now.year,now.month,now.day)
pen.write( hello,'center',font = font )
while True:
game.update()
time.sleep (1)
now = ti.datetime.now()
draw_clock(now.hour,now.minute,now.second)
game. mainloop()
求评价
|