【发布时间】:2020-10-07 18:34:42
【问题描述】:
我目前使用 Tkinter 构建了时钟和时针、分针和秒针。
hour_num = [3, 2, 1, 12, 11, 10, 9, 8, 7, 6, 5, 4]
for i in hour_num:
text_x = ORIGIN[0] + clock_radius * math.cos(theta)
text_y = ORIGIN[1] - clock_radius * math.sin(theta)
theta += d_theta
screen.create_text(text_x, text_y, text=i, font="Arial 25", fill="white")
## Time info
hour = datetime.now().hour
minute = datetime.now().minute
second = datetime.now().second
secondhand = screen.create_line(ORIGIN[0], ORIGIN[1], ORIGIN[0], ORIGIN[1] - clock_radius + 50, width=13, fill="blue")
minutehand = screen.create_line(ORIGIN[0], ORIGIN[1], ORIGIN[0], ORIGIN[1] - clock_radius + 70, width=13, fill="green")
hourhand = screen.create_line(ORIGIN[0], ORIGIN[1], ORIGIN[0], ORIGIN[1] - clock_radius + 90, width=13, fill="red")
所以现在画布看起来像这样: Screenshot
有人可以帮我用当前时间制作时钟指针吗?
我尝试使用三角函数来找出每小时之间的距离(取角与原点的余弦比)。首先,我意识到它不是完美的直角三角形,其次。时针将不现实:2:50 的时针将更接近 3 而不是 2。
谢谢
【问题讨论】:
-
您可以同时使用小时和分钟来计算时针的角度。
标签: python-3.x tkinter