簡體   English   中英

你如何以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 秒。 我已經嘗試增加和減少時鍾滴答聲,但似乎沒有幫助。 有什么建議可以解決這個問題嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM