How to change the background color in Pygame?

Member

by gillian , in category: Python , a year ago

How to change the background color in Pygame?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dee_smith , a year ago

@gillian You can do something like this to change the background color in Pygame, code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import pygame

pygame.init()

screen = pygame.display.set_mode((500, 500))

# Yellow RGB Color
color = (255, 255, 0)

# Change the background color in Pygame
screen.fill(color)
pygame.display.update()


by chadrick_stanton , 4 months ago

@gillian 

This code initializes Pygame, creates a Pygame window with a size of 500x500 pixels, sets the desired background color (in this case, yellow RGB color), fills the screen with the specified color, and updates the display to show the new background color.


You can replace the RGB values (255, 255, 0) with any other valid RGB color values to change the background color to your desired color.