Pygame语法错误

时间:2018-03-20 19:40:44

标签: python pygame

这就是说我在pygame.draw.line上有一个语法错误,我无法弄清楚如何摆脱错误。

import pygame
import sys
import random

oldx = 0
oldy = 0
x = 0
y = 0

lineColor = (255, 255, 255)

lineSize = 1

screen = pygame.display.set_mode ((320, 200))

screen.fill ((0, 0, 0))

while True:
    for event in pygame.event.get():

        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

        elif event.type == pygame.MOUSEBUTTONDOWN:
            print ("You presses the " + (str) (event.button) + "button.")

        elif event.type == MOUSEBUTTONUP:
            print ("You released the " + (str) (event.button) + "button.")

        elif event.type == pygame.MOUSEMOTION:
            oldx = x
            oldy = y
            x, y = event.pos

            print ("You moved the mouse to (" + str(x) + " , " + str(y) + ")")
        elif event.type == pygame.KEYDOWN:

            if event.type == org('a'):
                lineColor = (0, 0, 255)

            elif event.key == ord('s'):
                lineColor = (0, 255, 0)

            elif event.key == 32:
                lineColor = (random.radint (0, 255), random.radint (0, 255), random.radint (0, 255)

        pygame.draw.line (screen, lineColor, (oldx, oldy), (x, y), lineSize)

        pygame.display.flip()

我尝试过移动代码,但没有任何方法可以解决这个问题。我试过移动这条线以匹配不同的if和elif线,但我似乎无法弄明白。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你在这一行上缺少一个尾随')':

lineColor = (random.radint (0, 255), random.radint (0, 255), random.radint (0, 255)