首页 > 解决方案 > AttributeError:模块'pygame.event'没有属性'type'

问题描述

我正在从“编写这个游戏”中学习 python,在我第一次尝试时遇到了一个错误:

AttributeError:模块'pygame.event'没有属性'type'

源代码如下:

import pygame
from pygame import *
pygame.init()
WINDOW_WIDTH = 900
WINDOW_HEIGHT = 400
WINDOW_RES = (WINDOW_WIDTH, WINDOW_HEIGHT)
GAME_WINDOW = display.set_mode(WINDOW_RES)
display.set_caption('Attack of the Vampire Pizzas!')
game_running = True
while game_running:
    for events in pygame.event.get():
        if event.type == QUIT:
            game_running = False

    display.update()
pygame.quit()

谢谢!!丹麦

标签: python-3.x

解决方案


您必须将“”编辑event.type为“ events.type

if events.type == QUIT:

推荐阅读