gpt4 book ai didi

python - 游戏错误 : 'pygame' has no attribute 'init'

转载 作者:太空宇宙 更新时间:2023-11-04 10:17:44 25 4
gpt4 key购买 nike

我刚刚下载了 Pygame,但遇到了错误:AttributeError:模块“pygame”没有属性“init”。我在 stackoverflow 上环顾四周,有人通过重命名文件(我不知道该怎么做)来修复错误。目录如下

Python -> Lib -> 站点包 ->pygame

让我感到困惑的部分是在 pygame 文件夹中

pygame > Include, Lib
Include > pygame > (many hh files)
Lib > SitePackages > pygame > init (I know that it has the attribute init)

因为有 '3' pygame 文件夹,这会导致我的程序出错吗?

import pygame, sys
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()

最佳答案

例如,只需将文件从 pygame.py 重命名为 myTestGame.py;因为当您使用 import pygame 时,您正在导入相同的文件!

关于python - 游戏错误 : 'pygame' has no attribute 'init' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34343894/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com