我正在用 pygame、datetime 和 math 制作一个模拟时钟程序,但是指针所在的角度都关闭了,秒针走得太快了。这是代码:
import pygame
from datetime import datetime
from datetime import time
from datetime import timedelta
import math
import time
pygame.init()
white = (255, 255, 255)
black = (0, 0, 0)
display_width = 400
display_height = 400
gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('Clock')
gameDisplay.fill(white)
clock = pygame.time.Clock()
clock_radius = 200
clock_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'))
相关分类