我在pygame.draw.rect(screen, (0, 255, 0), (200, 150, 100, 50), 2)
上收到错误
即使我复制粘贴了命令语法并放置了我的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()
错误:
File "PATH(not giving it)", line 30
pygame.draw.rect(screen,(0,255,0),(200,150,100,50),2)
^
SyntaxError: invalid syntax
答案 0 :(得分:5)
在我看一下之前,我认为错误pygame.draw
调用#rect= ((32*int(x/32),(32*int(y/32)),32,32)
上面的行实际上没有在您的代码中注释掉。它在开头有一个额外的(
,导致下一行pygame.rect
的语法错误。