Python Forum

Full Version: pygame.Surface.fill help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do I fill the screen a certain color? I followed an example off of GitHub, but for some reason it is not doing anything. Any advice?
import pygame

(pygame.surface.Surface((800, 600)).fill((0, 255, 0)))
I am not getting an error, so I do not know why the screen stays white.
I don't use pygame but for what I can see you should do import pygame.surface.

And you have one parenthesis at the beginning which should be removed and one extra parenthesis at the back too.
First you need to init pygame.
pygame.init()
Second you need to create main surface.
main_surface = pygame.display.set_mode((800, 600))
You can now fill main_surface.
main_surface.fill(pygame.Color('green'))
third you need a main loop or a delay with pygame.display.flip() to see screen. Else it will just close.

Example
import pygame

pygame.init()
main_surface = pygame.display.set_mode((800, 600))
main_surface.fill(pygame.Color('green'))
pygame.display.flip()
pygame.time.delay(3000) # 3 seconds
Would you be willing to clarify what you mean by the loop?

Never mind, I just forgot to put parentheses after pygame.display.update