问题描述
import pygame
from pygame import *
pygame.init()
screen_width = 1000
screen_height= 1000
pygame = pygame.display.set_mode((screen_width,screen_height))
run= True
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run= False
pygame.quit()
我运行了这个命令,但在 for event in pygame.event.get():
中我收到一个错误
Exception has occurred: AttributeError 'pygame.Surface' object has no attribute 'event'
。 请帮帮我!!
解决方法
问题是由线路引起的
pygame = pygame.display.set_mode((screen_width,screen_height))
与显示关联的Surface 对象与pygame
模块同名。因此,Surface 对象 pygame
遮蔽了模块 pygame
。
您必须更改显示表面的名称:
pygame_surf = pygame.display.set_mode((screen_width,screen_height))