如何以 00:00 格式显示时间?目前,它以十进制格式显示时间
how do you display time in the format 00:00? Currently, it displays the time in a decimal format
计时器可以工作,但我无法以 00:00 格式显示它 - 目前,它以十进制格式显示时间,例如:2.547959356:688.9846939
while True: # main game loop
mouseClicked = False
DISPLAYSURF.fill(BGCOLOR) # drawing the window
drawBoard(mainBoard, revealedBoxes)
counting_time = pygame.time.get_ticks() - start_time
# change milliseconds into minutes, seconds
counting_seconds = str(counting_time/1000 ).zfill(2)
counting_minutes = str(counting_time/60000).zfill(2)
counting_string = "%s:%s" % (counting_minutes, counting_seconds)
counting_text = font.render(str(counting_string), 1, (0,0,0))
DISPLAYSURF.blit(counting_text,(350,3))
pygame.display.update()
clock.tick(25)
while True: # main game loop
mouseClicked = False
DISPLAYSURF.fill(BGCOLOR) # drawing the window
drawBoard(mainBoard, revealedBoxes)
########TIMER######
# Calculate total seconds
total_seconds = frame_count // frame_rate
# Divide by 60 to get total minutes
minutes = total_seconds // 60
# Use modulus (remainder) to get seconds
seconds = total_seconds % 60
# Use python string formatting to format in leading zeros
output_string = "Time: {0:02}:{1:02}".format(minutes, seconds)
text = font.render((output_string), True, (0,0,0))
DISPLAYSURF.blit(text,(350,3))
frame_count += 1
# Limit frames per second
clock.tick(20)
#update the screen with timer.
pygame.display.flip()
没关系,我想通了。但是,计时器增加 1 秒需要 4-5 秒。我已经尝试增加和减少时钟滴答声,但似乎无济于事。有什么解决这个问题的建议吗?
计时器可以工作,但我无法以 00:00 格式显示它 - 目前,它以十进制格式显示时间,例如:2.547959356:688.9846939
while True: # main game loop
mouseClicked = False
DISPLAYSURF.fill(BGCOLOR) # drawing the window
drawBoard(mainBoard, revealedBoxes)
counting_time = pygame.time.get_ticks() - start_time
# change milliseconds into minutes, seconds
counting_seconds = str(counting_time/1000 ).zfill(2)
counting_minutes = str(counting_time/60000).zfill(2)
counting_string = "%s:%s" % (counting_minutes, counting_seconds)
counting_text = font.render(str(counting_string), 1, (0,0,0))
DISPLAYSURF.blit(counting_text,(350,3))
pygame.display.update()
clock.tick(25)
while True: # main game loop
mouseClicked = False
DISPLAYSURF.fill(BGCOLOR) # drawing the window
drawBoard(mainBoard, revealedBoxes)
########TIMER######
# Calculate total seconds
total_seconds = frame_count // frame_rate
# Divide by 60 to get total minutes
minutes = total_seconds // 60
# Use modulus (remainder) to get seconds
seconds = total_seconds % 60
# Use python string formatting to format in leading zeros
output_string = "Time: {0:02}:{1:02}".format(minutes, seconds)
text = font.render((output_string), True, (0,0,0))
DISPLAYSURF.blit(text,(350,3))
frame_count += 1
# Limit frames per second
clock.tick(20)
#update the screen with timer.
pygame.display.flip()
没关系,我想通了。但是,计时器增加 1 秒需要 4-5 秒。我已经尝试增加和减少时钟滴答声,但似乎无济于事。有什么解决这个问题的建议吗?