Pygame Screen Color Won't Change

0 Anthony Chavez · July 6, 2015
Hello everyone, I just started working with Pygame, the thing is, I can't seem to be able to change the color of the window. The color only changes when I close the window. If anyone could help me out, that would be great, thanks. On a Mac, the screen is white, on Windows, it's black, I can't change the color on either.


import pygame
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
black = (0, 0, 0)
white = (255, 255, 255)
pygame.init()
Display = pygame.display.set_mode((400, 300))
pygame.display.set_caption("Snake")
running = True
while running is True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False


Display.fill(green)
pygame.display.update()

pygame.quit()
quit()



Post a Reply

Replies

Oldest  Newest  Rating
0 Otto Von Chesterfield · July 8, 2015
I haven't even bothered counting how many times I made mistakes like that.

I'm always here to help!
0 Anthony Chavez · July 8, 2015
Thanks guys. I eventually figured it out, I felt so stupid afterwards. lol
0 Ebenezer Popoola · July 7, 2015
This is the correct way to write the code because anything you want the game to do should be included when it is running.


import pygame
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
black = (0, 0, 0)
white = (255, 255, 255)
pygame.init()
Display = pygame.display.set_mode((400, 300))
pygame.display.set_caption("Snake")
running = True
while running is True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

Display.fill(green)
pygame.display.update()


#Display.fill(green)
#pygame.display.update()
+1 Otto Von Chesterfield · July 6, 2015
You're calling Display.fill(green) and pygame.display.update() after your main loop. If you call it right before, like so:


import pygame
#...
#...
running = True

Display.fill(green) #Fills the screen
pygame.display.update() #Tells pygame to draw

while running is True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
 #You should probably call it right here.


pygame.quit()
quit()

You should call it in the main loop as by custom in pygame, but since you're not changing anything visible in your program, you can just call it once right before the loop.
  • 1

Python

107,265 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator