Python Forum
[PyGame] pygame.Surface.fill help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] pygame.Surface.fill help
#1
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.
Reply
#2
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.
Reply
#3
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
99 percent of computer problems exists between chair and keyboard.
Reply
#4
Would you be willing to clarify what you mean by the loop?

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,308 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  [PyGame] Pygame is treating blob_group as a surface, when I need it to treat it as a Sprite. Swagford 1 1,302 Jan-24-2023, 09:58 PM
Last Post: metulburr
  Coloring a surface with transparency Sandor 4 2,313 Jan-02-2022, 08:11 AM
Last Post: Sandor
  Drawn line shift when that surface is copied to another in pygame Leo_Red 4 3,342 Feb-11-2021, 06:33 AM
Last Post: Leo_Red
  pygame.surface Graham 10 8,479 Nov-29-2018, 04:45 PM
Last Post: nilamo
  [PyGame] PLEASE HELP! TypeError: unsupported operand type(s) for +: 'pygame.Surface' and 'int' keyfive 1 5,286 Jun-19-2018, 01:20 PM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020