ArrayCreator
ArrayCreator

Reputation: 93

Pygame.draw.rect invalid syntax

I get an error on the pygame.draw.rect(screen, (0, 255, 0), (200, 150, 100, 50), 2) even though I copy-pasted the command syntax and just placed my vars.

    #! /usr/bin/env python
import pygame, sys
from pygame.locals import *
clock = pygame.time.Clock()
LEFT=1
width= 1000
height=500
running =1
x = 0
y = 0
isdown = False
screen = pygame.display.set_mode((width, height))
while running:
    for event in pygame.event.get():
        #screen.fill((90,90,90))
        if event.type == pygame.QUIT:
            running=0
        if event.type ==pygame.MOUSEBUTTONDOWN and event.button== LEFT:
            isdown = True
            t=event.pos
            x,y=t
        if event.type == pygame.MOUSEMOTION:
            if isdown:
                t=event.pos
                x,y=t
        if event.type ==pygame.MOUSEBUTTONUP and event.button== LEFT:
            isdown=False
    if isdown:
        #rect= ((32*int(x/32),(32*int(y/32)),32,32)
        pygame.draw.rect(screen,(0,255,0),(200,150,100,50),2)
    clock.tick(3000)
    pygame.display.flip()

The error:

  File "PATH(not giving it)", line 30
    pygame.draw.rect(screen,(0,255,0),(200,150,100,50),2)
         ^
SyntaxError: invalid syntax

Upvotes: 2

Views: 782

Answers (1)

famousgarkin
famousgarkin

Reputation: 14116

As I take a look at it, I think the line above erring pygame.draw call, #rect= ((32*int(x/32),(32*int(y/32)),32,32), is actually not commented out in your code. It has an extra ( at the beginning which results in the syntax error with pygame.rect on the following line.

Upvotes: 5

Related Questions