为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的python模拟时钟的指针显示错误的时间?

为什么我的python模拟时钟的指针显示错误的时间?

拉丁的传说 2021-06-07 06:24:58
我正在用 pygame、datetime 和 math 制作一个模拟时钟程序,但是指针所在的角度都关闭了,秒针走得太快了。这是代码:import pygamefrom datetime import datetimefrom datetime import timefrom datetime import timedeltaimport mathimport timepygame.init()white = (255, 255, 255)black = (0, 0, 0)display_width = 400display_height = 400gameDisplay = pygame.display.set_mode((display_width, display_height))pygame.display.set_caption('Clock')gameDisplay.fill(white)clock = pygame.time.Clock()clock_radius = 200clock_center = int(display_width / 2), int(display_height / 2)def main():    for event in pygame.event.get():        if event.type == pygame.QUIT:            quit()    # Drawing the clock and its center.    pygame.draw.circle(gameDisplay, black, clock_center, clock_radius, 5)    pygame.draw.circle(gameDisplay, black, clock_center, 5, 0)    pygame.display.update()    # I move the hands by drawing a white line over the previous line    # and then drawing the new line (which is a hand), so I need a    # variable equal to the time one second ago (for the white line) as    # well as the current time (for the current hand).    now_hour = int(datetime.now().strftime('%I'))    now_minute = int(datetime.now().strftime('%M'))    now_second = int(datetime.now(). strftime('%S'))    one_sec_ago_hour = int((datetime.now() - timedelta(seconds=1)).strftime('%I'))    one_sec_ago_minute = int((datetime.now() - timedelta(seconds=1)).strftime('%M'))    one_sec_ago_second = int((datetime.now() - timedelta(seconds=1)).strftime('%S'))
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 189 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信