Pages

Se afișează postările cu eticheta clock. Afișați toate postările
Se afișează postările cu eticheta clock. Afișați toate postările

luni, 2 ianuarie 2023

PyGame : simple digital clock.

This is the source code I used and is very simple.
import pygame
import time

# init the Pygame
pygame.init()

# this set the window size
window_size = (640, 100)

# this create the window
screen = pygame.display.set_mode(window_size)

# this set the title of the window
pygame.display.set_caption("Digital Clock")

# this fill the background color to white
screen.fill((255, 255, 255))

# settings for the font and size
font = pygame.font.Font(None, 36)

# the game loop area
running = True
while running:
# use an event to quit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # get the current time
    current_time = time.strftime("%H:%M:%S")

    # render the time as text
    text = font.render(current_time, True, (0, 0, 0))

    # clear the screen
    screen.fill((255, 255, 255))

    # draw the text on the screen
    screen.blit(text, (10, 10))

    # update the screen
    pygame.display.flip()

# quit Pygame application
pygame.quit()
The result of the running source code is this: