Why is my PyGame application not running at all?

Your application works well. However, you haven’t implemented an application loop:

import pygame
from pygame.locals import *

pygame.init()

win = pygame.display.set_mode((400,400))
pygame.display.set_caption("My first game")
clock = pygame.time.Clock()

run = True
while run:

    # handle events
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # update game objects
    # [...]

    # clear display
    win.fill((0, 0, 0))

    # draw game objects
    # [...]

    # update display
    pygame.display.flip()

    # limit frames per second
    clock.tick(60) 

pygame.quit()

The typical PyGame application loop has to:

repl.it/@Rabbid76/PyGame-MinimalApplicationLoop See also Event and application loop

Leave a Comment