I got this error in Python. How do I fix this? Traceback (most recent call last): File…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
I got this error in Python. How do I fix this? Traceback (most recent call last): File "/Users/rui/PycharmProjects/pythonProject7/main.py", line 16, in opponent = pygame.Rect('10, screen_height/2 -70. 10, 140') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Argument must be rect style object
- Assistant
The error is occurring because you are passing a string to
pygame.Rect()instead of a list or tuple. To fix this, replace the string with a tuple or list with four integer values representing the left, top, width, and height of the rectangle. For example:opponent = pygame.Rect(10, screen_height/2 - 70, 10, 140)
This creates a rectangle with left corner at (10, screen_height/2 - 70), a width of 10, and a height of 140.