python海龟画图钟表
时间: 2023-11-07 11:05:53 浏览: 148
python海龟画图钟表的实现可以参考以下示例代码:
```python
import turtle
import datetime
# 设置窗体大小
turtle.setup(600, 600)
# 隐藏箭头
turtle.hideturtle()
# 绘制表盘
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.circle(200)
# 绘制刻度
turtle.penup()
turtle.goto(0, 0)
turtle.setheading(90)
for _ in range(12):
turtle.penup()
turtle.forward(170)
turtle.pendown()
turtle.forward(30)
turtle.penup()
turtle.goto(0, 0)
turtle.right(30)
# 绘制时针、分针、秒针
current_time = datetime.datetime.now()
hour = current_time.hour % 12
minute = current_time.minute
second = current_time.second
# 时针
turtle.penup()
turtle.goto(0, 0)
turtle.setheading(90)
turtle.right(hour * 30 + minute * 0.5)
turtle.pendown()
turtle.forward(100)
# 分针
turtle.penup()
turtle.goto(0, 0)
turtle.setheading(90)
turtle.right(minute * 6 + second * 0.1)
turtle.pendown()
turtle.forward(150)
# 秒针
turtle.penup()
turtle.goto(0, 0)
turtle.setheading(90)
turtle.right(second * 6)
turtle.pendown()
turtle.forward(180)
# 不关闭窗体
turtle.mainloop()
```
阅读全文