I have searched thoroughly before posting this. I seem to have a 'module' object not callable error. Here is my code:
""" Create Snake """
def createSnake():
x = randrange(0, 720, 20)
y = randrange(0, 480, 20)
size = 3
snakeBox = ""
snake = []
for i in range(size):
snakeBox = pygame.rect((x + 20*size, y + 20*size), (20, 20))
snake.append(snakeBox)
return snake
This is the error I recieve on execution:
root@raspberrypi:/home/pi/Codes/Snake# python Snake.py
Traceback (most recent call last):
File "Snake.py", line 108, in <module>
if __name__ == '__main__': main()
File "Snake.py", line 106, in main
gameScreen()
File "Snake.py", line 95, in gameScreen
game()
File "Snake.py", line 57, in game
snake = createSnake()
File "Snake.py", line 49, in createSnake
snakeBox = pygame.rect((x + 20*size, y + 20*size), (20, 20))
TypeError: 'module' object is not callable
I cannot seem to figure out what the error is as I think I have imported my modules correctly
from pygame.locals import *
Thank you for your help :')
pygame.rect
is itself a module, not an object. That module contains aRect
object, which is what you do want to call. See falsetru's answer. – TheSoundDefense Aug 7 '14 at 15:04