Pygame: drawing rectangle on a surface

I’m on mobile right now, and IOS likes to change those quotes. For the formatting, I did do that with python.

For the error message:

Traceback (most recent call last):
  File “src/”, line 32, in <module>
  File “…/src/”, line 12, in drawNpcs
    pygame.Rect(self.surface, pygame.color(“#000000”), (20, 20, self.drawWidth - 20, self.drawHeight - 20))
TypeError: ‘module’ object is not callable

The first … is the text that always appears in terminal when using pygame.
The second … is it printing the entire directory.

1 Like

lol i cant fix it

error message:

(Everything else above is the same as the last error message)
TypeError: Argument must be rect style object

im just gonna go for now

For this error, you are trying to create a Rect from a surface, color, and a tuple of 4 ints. You cannot create a Rect with a surface or a color.

Perhaps you meant:

self.surface.fill("#000000", (20, 20, self.drawWidth - 20, self.drawHeight - 20))
# or nearly equivalently:
pygame.draw.rect(self.surface, "#000000", (20, 20, self.drawWidth - 20, self.drawHeight - 20))

Read the docs:


I changed pygame.draw.rect() to pygame.Rect() when I was having the module call error. Thank you, wish I could mark two solutions. I have no errors now, and it’s drawing the black rect as well. Like I always do, I forgot that width and height for reacts should be x - 40 and not x - 20


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.