-1

I'm very new to python and I've been following Tech With Tim's pygame tutorial, but my window isn't responding or closing. I'm using a mac and I don't know if that changes anything... and I keep getting the error message

Error:

function missing required argument 'rect' (pos 3).

Code:

import pygame
pygame.init()

win = pygame.display.set_mode((500, 500))

pygame.display.set_caption("First game")

x = 50
y = 50
width = 40
height = 60
vel = 5

run = True
while run:
    pygame.time.delay(100)

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

    keys = pygame.key.get_pressed()

    if keys[pygame.K_LEFT]:
        x -= vel
    if keys[pygame.K_RIGHT]:
        x += vel
    if keys[pygame.K_UP]:
        y -= vel
    if keys[pygame.K_DOWN]:
        y += vel
    
    pygame.draw.rect(win, (255, 0, 0))
    pygame.display.update()

pygame.quit()
ASLAN
  • 629
  • 1
  • 7
  • 20
4ntoine12
  • 11
  • 2

2 Answers2

1

rect function takes at least three arguments, only 2 were given:

pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))

It should work on mac too

Check pygame docs for reference : https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect

Nine Tails
  • 378
  • 3
  • 15
0

Actually you have not typed it's height width x position and y position where you drew the rectangle do this

pygame.draw.rect(win, (255, 0, 0), (x, y, height, width)) 

You have x, y, height, width already defined this should work.

Ran Marciano
  • 1,431
  • 5
  • 13
  • 30