Reputation: 33235
I'm following an example in a pygame tutorial:
import pygame
pygame.init()
surf = pygame.display.set_mode((400, 450))
#surf.fill((255, 0, 0))
surf.fill(pygame.Color(255, 0, 0))
pygame.display.update()
input()
As you can see, I've tried two ways:
Neither works for me.
My working environment is macOS, the version of pygame is 1.9.6, the version of Python is 3.8.
What I saw:
Why is the background color not changed?
Upvotes: 2
Views: 1379
Reputation: 11
I faced the same problem recently. I am using MacOS 10.15.7 and tried versions from 2.0.0 through 2.0.3dev4 of Pygame installed via Pip. Nothing worked. Until I read the following text in the Pygame documentation (https://www.pygame.org/docs/ref/color.html):
Color objects support equality comparison with other color objects and 3 or 4 element tuples of integers. There was a bug in pygame 1.8.1 where the default alpha was 0, not 255 like previously.
So, defining the RGB color with a 4 elements tuple (last number the alpha value, 255 opaque) solved the problem.
Upvotes: 0
Reputation: 33235
After searching for "pygame fill doesn't work" for a while and trying each one of the suggested answers, I found out that the only way to make the background color change happen is to upgrade pygame
to 2.0.0.dev4
.
Since by default pip
only installs the most recent stable version of a package, I need to specify the version explicitly like pip install pygame==2.0.0.dev4
.
And now I can see the red background.
Upvotes: 3
Reputation: 111
import pygame
pygame.init()
surf = pygame.display.set_mode((400, 450))
run = True
clock = pygame.time.Clock()
while run:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#surf.fill((255, 0, 0))
surf.fill(pygame.Color(255, 0, 0))
pygame.display.update()
Upvotes: 3