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
0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

You are right but that error will only occur after the NoneType error was fixed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.