Reputation: 113
I'm just learning GUI programming using python 3.2 and pygame 1.8. From what I understand the following code should display a white background. However all I get is a black screen. Also, I'm using IDLE in Windows 7 if that matters:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
Upvotes: 2
Views: 5825
Reputation: 227
You don't blit the backgound you just put the fill part in the loop. Also you are forgetting the pygame.display.update()
Upvotes: 1
Reputation: 41
You forgot to update the screen.
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
Upvotes: 2
Reputation: 117641
You must have a main loop that updates the screen. This code should work:
import pygame
pygame.init()
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
while True:
screen.blit(background, (0, 0))
pygame.display.update()
Upvotes: 4