turtle模拟时钟_面向对象_TimePointer类

"""这是一个用海龟模块制作的模拟时钟程序,作者:李兴球,日期:2018/9/21于郑州"""

from turtle import *
from time import *

def init_screen():
    
    screen = Screen()
    screen.title("模拟时钟_python海龟画图模块制作_by_李兴球")
    screen.delay(0)
    screen.mode("logo")     #此模式刚好和时钟转动相适配
    pointer = ((0,0),(5,0),(5,50),(10,50),(0,60),(-10,50),(-5,50),(-5,0)) #顶点表
    screen.addshape("pointer",pointer)                        #添加大箭头各顶点到形状列表
    
    return screen
    
def draw_digital():
    
    #以下代码画时钟的数字
    radius = 300
    draw_turtle = Turtle(visible=False,shape='circle')

    draw_turtle.penup()
    draw_turtle.setheading(30)
    for i in range(1,13):
        draw_turtle.fd(radius)
        draw_turtle.write(str(i),align="center",font=(None,18,"normal"))
        draw_turtle.bk(radius)
        draw_turtle.right(30)
    draw_turtle.showturtle()

        
本文隐藏内容 登陆 后才可以浏览
if __name__ == "__main__": screen = init_screen() draw_digital() hpointer = TimePointer((1.3,3.5),"red") # 生成时钟指针 hpointer.run_hour() mpointer = TimePointer((0.8,4.2),"orange") # 生成分钟指针 mpointer.run_minute() spointer = TimePointer((0.5,4.3),"blue") # 生成秒钟指针 spointer.run_second() screen.mainloop()