我在 pygame.draw.rect(screen, (0, 255, 0), (200, 150, 100, 50), 2) 上遇到错误
即使我复制粘贴了命令语法并只是放置了我的变量。
#! /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
最佳答案
当我查看它时,我认为上面的行错误 pygame.draw
调用,#rect= ((32*int(x/32),(32*int (y/32)),32,32)
实际上没有在代码中注释掉。它的开头有一个额外的 (
,这会导致 语法错误pygame.rect
在下面一行。
关于python - Pygame.draw.rect 语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24341363/