【问题标题】:while executing the alien_invasion getting this error. How to get rid of this?在执行 alien_invasion 时收到此错误。如何摆脱这个?
【发布时间】:2018-05-24 10:19:20
【问题描述】:
import pygame
import sys


def run_game():
    pygame.init()
    screen = pygame.display.set_mode((1200,800))
    pygame.display.set_caption("Alien Invasion")
    bg_color = (230, 230, 230)

while True:
    screen.fill(bg_color)
    for event in pygame.event.get():
        if event.type() == pygame.QUIT:
            sys.exit()
    pygame.display.flip()
run_game()

这是我遇到的错误:

Traceback(最近一次通话最后一次):

文件“”,第 19 行,在 run_game()

文件“”,第 14 行,在 run_game 中 if event.type() == pygame.QUIT:

TypeError: 'int' 对象不可调用

if event.type() == pygame.QUIT:

如果我一直这样,我也会出错

【问题讨论】:

    标签: python-3.x pygame


    【解决方案1】:

    看起来event.type是一个整数,不是函数,所以试试:

    if event.type == pygame.QUIT:
    

    【讨论】:

      猜你喜欢
      • 2015-04-29
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多