import pygame
import time

# Initialize Pygame
pygame.init()

# Set up the screen (just to have a window open)
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("Pygame User Events Example")

# Define a custom user event
print_message_event = pygame.USEREVENT + 1  # Event ID will be 25

# Set up a timer to trigger the event every 3 seconds (3000 milliseconds)
pygame.time.set_timer(print_message_event, 3000)

# Game loop
running = True
while running:
    # Process events in the event queue
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        
        # Check for the custom user event
        if event.type == print_message_event:
            print("Hello World")  # Print message every 3 seconds
    
    # Fill the screen with a color (just for visualization)
    screen.fill((0, 0, 0))
    pygame.display.flip()

    # Delay to make sure the window doesn't close too quickly
    pygame.time.delay(100)

# Stop the timer when exiting
pygame.time.set_timer(print_message_event, 0)

# Quit Pygame
pygame.quit()