TypeError: rect argument is invalid in Pygame

Hello everyone! I am trying to make a snake in pygame but i came across an error that said:

TypeError: rect argument is invalid

Does anyone know how to fix this?


The argument of the pygame.draw.rect function, which is defined as a list in your code, must be a tuple. In addition, you placed this argument outside the brackets, which is incorrect, and the color of the rectangle is not specified in the tuple.

Corrected drawing code:

pygame.draw.rect(game_screen, (255, 255, 255), (x, y, 10, 10))

Welcome to the community @amellietjes900. I am not able to help you with this but we have a lot of others that are really good at coding. Just wanted to welcome you to the community! Hope you enjoy your time!

1 Like

Wouldn’t pygaame.Rect(x, y, 10, 10) also work?

1 Like

Yes, that should also work.

1 Like

@amellietjes900 is your problem solved? If so please mark this post as the solution.

Thank you all for the replies. Ive tried following the steps recommended to me, but it still didn’t work :woozy_face:(

Are you still getting the same error?

I did get the same error, again.

Can you send your full code? Be sure to wrap it in a code block

# your code here
1 Like
pygame.draw.rect (game_screen,255,0,0), [food_x,food_y,10,10]

That’s not your full code. Also, it doesn’t seem you took @KAlexK’s suggestion.

Replace this code with this one:

pygame.draw.rect(game screen, (255, 0, 0), (food_x, food_y, 10, 10))

You forgot to put an opening parenthesis before 255.

You need to delete line 24.

1 Like

Okay, I did the delete line 24 now. I am able to see the red dot now in the game but not the moving one.
Is the code now right u think? I hope I followed the steps right.

As the error says, you need to replace pygame.DOWN with pygame.K_DOWN.

1 Like