python罗盘时钟代码
时间: 2023-11-08 07:59:33 浏览: 192
以下是一个用Python编写的罗盘时钟的代码示例:
```python
import turtle
import datetime
# 设置乌龟的形状为箭头
turtle.shape("arrow")
# 绘制外圆
turtle.penup()
turtle.goto(0, -200)
turtle.pendown()
turtle.circle(200)
# 绘制内圆
turtle.penup()
turtle.goto(0, -150)
turtle.pendown()
turtle.circle(150)
# 绘制时钟刻度
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
for i in range(12):
turtle.penup()
turtle.goto(0, 0)
turtle.right(i * 30)
turtle.forward(180)
turtle.pendown()
turtle.forward(20)
turtle.penup()
turtle.goto(0, 0)
# 获取当前时间
now = datetime.datetime.now()
hour = now.hour
minute = now.minute
second = now.second
# 绘制时针
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.right(hour * 30 + minute / 2)
turtle.forward(100)
# 绘制分针
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.right(minute * 6 + second / 10)
turtle.forward(150)
# 绘制秒针
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.right(second * 6)
turtle.forward(180)
turtle.done()
```
阅读全文