how to make image/images disappear in pygame?

You can not remove an image. You have to redraw the entire scene (including the background) in the application loop. Note the images are just a buch of pixel drawn on top of the background. The background “under” the images is overwritten and the imformation is lost:

The main application loop has to:

A minimum application is

import pygame

pygame.init()

window = pygame.display.set_mode((500, 500))
clock = pygame.time.Clock()

# main application loop
run = True
while run:
    clock.tick(60)

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

    # update game states and move objects
    # [...]

    # clear the display
    window.fill(0) # or `blit` the back ground image instead

    # draw the scene - draw all the objects
    # [...]

    # update the display
    pygame.display.flip()

Leave a Comment