0

Using Python 3.11:

import pygame
import random

from pygame.locals import (
    K_UP,
    K_DOWN,
    K_LEFT,
    K_RIGHT,
    K_ESCAPE,
    KEYDOWN,
    QUIT,
)

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

running = True

while running:

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

        screen.fill((0, 0, 0))
        pygame.draw.rect(screen, (255, 255, 255), (250,250), 75)
        pygame.display.flip()

Does anyone know what the issue with my code is? Why it comes up with this error:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Documents\Python_Work\PYTHON_Folder_II\My Tests\2d Test.py", line 28, in <module>
    pygame.draw.rect(screen, (255, 255, 255), (250,250), 75)
TypeError: rect argument is invalid
Woodford
  • 3,746
  • 1
  • 15
  • 29
Sven
  • 7
  • 5
  • 3
    Check the documentation. `draw.rect` takes a surface, a color, and a rectangle. You have not provided a rectangle, you have simply provided a point. – Tim Roberts Aug 16 '23 at 22:21
  • @TimRoberts thankyou for explaining, Do you mean in the "pygame.draw.rect(screen, (255, 255, 255), (250,250), 75)", changing the variables? If so, can you please provide an example. Thanks :) – Sven Aug 16 '23 at 23:02
  • 2
    ??? Let me ask you this. Draw a rectangle with the coordinates (250,250). Could you do that? You can't, because there's not enough information. You need, for example, `pygame.Rect( 100, 100, 50, 50 )`, which specifies a rectangle that starts at 100,100 and is 50 wide and 50 tall. I don't know what you expect the 75 to be. – Tim Roberts Aug 17 '23 at 00:40

0 Answers0