原问题网址:https://stackoverflow.com/questions/39840580/python-attributeerror-module-pygame-has-no-attribute-display
问题:当一个小哥试图用python中的pygame创建一个窗口时出现了RT问题:
>>> 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'
问题原因可能有以下几个方面:
1.需要先使用
pygame.init()
2.确保自己的文件等命名中没有使用pygame.py或者pygame关键字
可以通过以下代码查询是否有此类文件:
import pygame
print('Path to module:',pygame._file_)
3.可能使用的pygame版本没有这个attribute
可以通过dir(pygame)函数来查看当前版本中包含哪些attribute