Pygame.init() 不工作

Paa*_*ara 0 python pygame init

我成功下载了 pygame 但现在当我这样做时:

import pygame
pygame.init()
size =  [400, 400]

pygame.display.set_mode(size)
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module> pygame.init AttributeError:
'module' object has no attribute 'init'
Run Code Online (Sandbox Code Playgroud)

没有什么对我有用。请帮我使用initdisplay

我在用

小智 5

您可能在键入
时将文件命名为 pygame.py :

import pygame
Run Code Online (Sandbox Code Playgroud)

python 不会导入您想要的 pygame 模块,而是会尝试导入本地模块 pygame - 您的文件。并且您的文件没有方法init。尝试将文件名从pygame.py更改为mypygame.py