2013-12-16 103 views
0

這是我的代碼,它在Pygame窗口繪製了一個網格,當我在學校的PC上運行這個窗口時它運行良好。現在,我想繼續在家裏一個錯誤出現,我不能找到一個解決方案自己:模塊沒有屬性來顯示

import sys, pygame 
pygame.init() 


white = (255, 255, 255) 
black = (0,0,0) 
orange = (255, 165,0) 
green = (0,128, 0) 
radius = 25 
screen = pygame.display.set_mode((715,715)) 
screen.fill(white) 
pygame.display.update() 

    def grid(): 
     pygame.draw.line(screen, (black), (60, 0), (60,715)) 
     pygame.draw.line(screen, (black), (360, 0), (360,715)) 
     pygame.draw.line(screen, (black), (0, 65), (715, 65)) 
     pygame.draw.line(screen, (black), (0, 130), (715, 130)) 
     pygame.draw.line(screen, (black), (0, 195), (715, 195)) 
     pygame.draw.line(screen, (black), (0, 260), (715, 260)) 
     pygame.draw.line(screen, (black), (0, 325), (715, 325)) 
     pygame.draw.line(screen, (black), (0, 390), (715, 390)) 
     pygame.draw.line(screen, (black), (0, 455), (715, 455)) 
     pygame.draw.line(screen, (black), (0, 520), (715, 520)) 
     pygame.draw.line(screen, (black), (0, 585), (715, 585)) 
     pygame.draw.line(screen, (black), (0, 650), (715, 650)) 
     pygame.draw.line(screen, (black), (0,715), (715, 715)) 
     pygame.display.update() 
grid() 
grid() 

當我運行這段代碼,我得到一個錯誤:

Traceback (most recent call last): 
    File "C:\Users\Jack\Documents\Jack's Stuff\School\Year 10\Computer Science\Programs\Jack's Python programs\Useful programs\pygame_test.py", line 1, in <module> 
    import sys, pygame 
    File "C:\Users\Jack\Documents\Jack's Stuff\School\Year 10\Computer   Science\Programs\Jack's Python programs\Useful programs\pygame.py", line 11, in <module> 
    screen = pygame.display.set_mode((715,715)) 
AttributeError: 'module' object has no attribute 'display' 

什麼我做錯了我的代碼,因爲我嘗試了幾個不同的東西?

+0

http://stackoverflow.com/questions/16638531/why-am-i-getting-this-attributeerror-python3-pygame – jonrsharpe

+0

無法得到它的工作 – user3100799

回答

1

模塊pygame在您的密碼正在被拿起。那是你需要的嗎?

+0

pygame的是我需要的模塊 – user3100799

+0

可以粘貼pygame代碼嗎? – Arovit

+0

我正在運行的所有代碼都是在我詢問的問題 – user3100799

0

你正在做的事情在你的代碼中很不尋常。你沒有實例化一個pygame類型的新對象。相反,您正在模塊上手動運行init,然後直接引用模塊。據推測這是導致你的錯誤。

試試這個

# rather than pygame.init() 
game = pygame 

# replace all future instances of "pygame" with "game" 
game.display.update() 
+0

剛剛嘗試過,並且出現相同的錯誤 – user3100799

相關問題