the background color of my program is only visable when I close the app icon

I have an app icon open but I can’ see a white background in my application window untill I close the app. What do I do?


import pygame

# Internationalizing Pygame
pygame.init()
# Title and Icon
pygame.display.set_caption("Space Invaders")
icon = pygame.image.load()
pygame.display.set_icon(icon)

# player
playerIMG = pygame.image.load()
playerX = 370
playerY = 30
screen = pygame.display.set_mode((1200, 600))


def player():
    screen.blit(playerIMG, (playerX, playerY))


running = True
while running:  # RGB
    screen.fill((222, 222, 222))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

player()
pygame.display.update()

I don’t know what to do.

>Solution :

It is a matter of Indentation you have to draw the scene and update the display in the application loop:

running = True
while running:  # RGB
    screen.fill((222, 222, 222))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

# INDENTATION
#-->|
    player()
    pygame.display.update()

Leave a Reply