python - Pygame.draw.rect 语法无效

标签 python pygame

我在 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/

相关文章:

python - 列表/数组表示 [] 和 {} 有什么区别?

python - 让pygame Sprite 在python中消失

python - pygame compile()预期字符串,不包含空字节

python - 值错误 : array is too big

python - 什么时候需要 pygame.init()?

python - 单击鼠标时不会绘制圆圈(pygame)

python - 如何在 python 中将图像 block 传输到特定图像的区域内?

python - 使用 autoretry_for 正确处理 Celery 异常

python - 带有多处理pathos库的简单Python程序

Python:关于数学和负幂的问题