[Python] 纯文本查看 复制代码 import turtle
from datetime import datetime
import random
turtle.mode('logo')
turtle.tracer(False)
#turtle.bgpic('bac2.gif')
#设置时间
#算法 == 数学
turtle.colormode(255)
def color():
r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)
c = (r,g,b)
return c
def Clock():
turtle.clear()
shijian = datetime.now()
print(shijian)
h = shijian.hour
m = shijian.minute
s = shijian.second
print(h,m,s)
#h = 360/12 =30
#m = 360/60 = 6
#s = 360/60 = 6
turtle.colormode(255)
turtle.bgcolor(0,0,0)
#时钟
turtle.pencolor(144, 238, 144)
turtle.pensize(20)
turtle.pu()
turtle.goto(0,0)
turtle.pd()
turtle.seth(360-h*3-90)
turtle.fd(100)
#分钟
turtle.pencolor(135, 206, 250)
turtle.pensize(12)
turtle.pu()
turtle.goto(0,0)
turtle.pd()
turtle.seth(m*6)
turtle.fd(120)
#秒钟
turtle.seth(s*6)
turtle.pencolor(69, 63, 127)
turtle.pensize(5)
turtle.pu()
turtle.goto(0,0)
turtle.pd()
turtle.seth(s*6)
turtle.fd(150)
x = 160
turtle.pensize(10)
for i in range(4):
turtle.pencolor(color())
turtle.pu()
turtle.goto(x,0)
turtle.pd()
turtle.seth(0)
turtle.circle(x)
x+=5
for i in range(1,13):
turtle.pu()
turtle.seth(30*(i-1)+28)
turtle.goto(-10,-10)
turtle.fd(200)
turtle.pd()
#turtle.seth(0)
turtle.write(i,font = (None,20))
turtle.pensize(5)
for i in range(60):
turtle.pu()
turtle.seth(6*(i)+28)
turtle.goto(0,0)
turtle.fd(150)
turtle.pd()
#turtle.seth(0)
turtle.fd(5)
turtle.ontimer(Clock,1000)
turtle.update()
t1 = '游人记得承平事'
t2 = '暗喜风光似昔年'
turtle.pu()
turtle.goto(-140,30)
turtle.pd()
turtle.color(color())
turtle.write(t1,font=(None,30))
turtle.pu()
turtle.goto(-140,-30)
turtle.pd()
turtle.color(color())
turtle.write(t2,font=(None,30))
Clock()
turtle.done() |