我开始使用Python,特别是模块pygame,但是当我尝试创建一个窗口时,会发生此错误
>>> import pygame
>>> (width, height) = (300, 200)
>>> screen = pygame.display.set_mode((width, height))
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
screen = pygame.display.set_mode((width, height))
AttributeError: module 'pygame' has no attribute 'display'
请帮助我。
最佳答案
您可能会用任何其他同名文件(例如可能位于同一文件中的 pygame.py)掩盖 pygame 库
如果您使用的是 Windows,只需在开始菜单的搜索框中搜索 pygame.py 即可。右键单击结果,然后单击“打开文件位置”。只需从文件夹中删除 pyagame.py 文件即可。 或者您可以通过以下方式打印有问题模块的路径:
import pygame
print('Path to module:',pygame._file_)
关于python 属性错误 : module 'pygame' has no attribute 'display' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39840580/