微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复“发生异常:AttributeError”

如何解决如何修复“发生异常:AttributeError”

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))

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。