0

I have the following problem in pygame.I got pygame surface usingsurf=pygame.display.get_ surface() ,but when I am trying to call

surf.fill()

It says:

None type have no attribute fill
user6012107
  • 65
  • 1
  • 9

2 Answers2

1

You have to set a display mode first with pygame.display.set_mode.

Otherwise, pygame.display.get_surface() will return None:

pygame.display.get_surface()
Get a reference to the currently set display surface
get_surface() -> Surface
Return a reference to the currently set display Surface. If no display mode has been set this will return None.

Also, you usually don't need that function, since set_mode already returns the display Surface.

sloth
  • 99,095
  • 21
  • 171
  • 219
0

I think your method "fill()" needs a color argument:

fill() fill Surface with a solid color fill(color, rect=None, special_flags=0) -> Rect

the documentation: https://www.pygame.org/docs/ref/surface.html#pygame.Surface.fill

  • You are right but that error will only occur after the `NoneType` error was fixed –  Mar 31 '16 at 09:07