Remove Picture From Screen in Pygame (Python)
To remove a picture from the screen in Pygame, you can simply fill the area of the screen where the picture is located with the background color. Here's an example:
import pygame
# Initialize Pygame
pygame.init()
# Set up the screen
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Remove Picture Example')
# Load the picture
picture = pygame.image.load('picture.jpg')
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the screen with background color
screen.fill((0, 0, 0)) # Change (0, 0, 0) to your desired background color
# Update the screen
pygame.display.flip()
# Quit Pygame
pygame.quit()
In this example, we use screen.fill((0, 0, 0)) to fill the entire screen with a black color. You can change (0, 0, 0) to a different RGB value to use a different background color.
Make sure to replace 'picture.jpg' with the actual path to your picture file.
原文地址: https://www.cveoy.top/t/topic/HFd 著作权归作者所有。请勿转载和采集!