"""这是一个用海龟模块制作的模拟时钟程序,作者:李兴球,日期: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') class TimePointer(Turtle): def __init__(self,size,color): Turtle.__init__(self,visible = False,shape = "pointer") def run_hour(self): hour = localtime(time()).tm_hour hour = hour % 12 def run_minute(self): minute = localtime(time()).tm_min def run_second(self): second = localtime(time()).tm_sec 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()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)