2016-10-03 68 views
0

我開始使用Python專門的模塊pygame的,但是當我嘗試創建一個窗口,出現此錯誤蟒蛇AttributeError的:模塊「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' 

請幫助我。

+2

您可能需要調用'pygame.init()'第一 – njzk2

+0

確保你沒有打電話給你自己的文件或文件夾'pygame.py'或者「pygame」。 – user2357112

+1

你的解釋器中必須有意外超影的pygame,或者你的項目中的本地必須有一些名爲pygame的東西。這個電話對我來說非常好。 – idjaw

回答

0

你可能被掩蓋pygame的庫具有相同名稱的任何其他文件,如pygame.py這可能是在同一個文件

如果您使用的是Windows,只是搜索pygame.py在搜索框中開始菜單。右鍵單擊結果並單擊「打開文件位置」。從文件夾中刪除pyagame.py文件。 或者你可以打印出錯的模塊由路徑:

import pygame 
    print('Path to module:',pygame._file_)