python 属性错误 : module 'pygame' has no attribute 'display'

标签 python pygame

我开始使用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/

相关文章:

python - 根据条件在行之间的 Pandas 中分组

python - 如何提高OpenCV中Haar级联的准确性?

Python BLE 发现所有 UUID 特征

python - pygame : Why does calling a function inside the game loop inside Game loop make my game lag?

osx-lion - 通过 Mac 在 PyPy 中安装 Pygame

python - 使用 pandas 根据文本条件将字符添加到列

python - 替换列表中的无值?

python - 如何在 XBOX One Controller 上拆分触发器?

python - 为什么 pygame 窗口不能正常关闭?

python - 如何在 pygame 中移动球而不是在屏幕上留下痕迹?