“‘Module’ object cannot be called” error in pygame

Question:
I’m tying to make a game using pygame (for once). I wanted to split it into multiple different files, but I had the error “‘Module’ object cannot be called” error. I looked online to find that this appears whenever you try to run a module, for example you use “import module” and then you try to run it like a function: module(). However, I couldn’t find any use of that in my code.

There may be additional issues with my code, but I don’t want any fixed for that.

Repl link:
I don’t develop this on replit.

Main.py:

import pygame
import gameDraw

pygame.init()
width, height = [1250, 750]
screen = pygame.display.set_mode((width, height)

clock = pygame.time.clock()
running = True
perspective = “menu

renderer = gameDraw.draw(screen, width, height)

# game loop
while running and perspective == “menu”:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        # edit width and height when screen is resized
        if event.type == pygame.VIDEORESIZE:
            width, height = (event.size)

    screen.fill(pygame.color(‘#FFFFFF’))

    if renderer.drawWidth != width:
        renderer.drawWidth = width

    if renderer.drawHeight != height:
        renderer.drawHeight = height
    
    renderer.drawNpcs()

    pygame.display.flip()
    clock.tick(60)

pygame.quit()

gameDraw.py:

import pygame

class draw():
    def __init__(self, surface, windowWidth, windowHeight):
        # self.pygame = pygame
        self.surface = surface
        self.drawWidth = windowWidth
        self.drawHeight = windowHeight
    def drawTiles(self):
        pass
    def drawNpcs(self):
        pygame.Rect(self.surface, pygame.color(“#000000”), (20, 20, self.drawWidth - 20, self.drawHeight - 20)) # error message says the error is here

lol discourse thinks that the # in the string is a comment

Hello, could you provide the full error message (which includes the line number)?

Also, when posting code, be sure that you are using the correct quotes "", not “”.
Also, indicate the language of the code block like so, so it formats properly:

```py
x = None
```

It looks like the problem is that you are using pygame.color, instead of pygame.Color.
pygame.color is a module, while pygame.Color is the class you should use.

Also note that in this case, passing in the string as a color is valid and there is no need to use pygame.Color.

3 Likes

4 posts were split to a new topic: Pygame: drawing rectangle on a surface

pygame.color was the problem, I changed it to Color and that error went away, only for me to fix another error… (not related to that or module calling)

1 Like

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