這是我的代碼,它在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'
什麼我做錯了我的代碼,因爲我嘗試了幾個不同的東西?
http://stackoverflow.com/questions/16638531/why-am-i-getting-this-attributeerror-python3-pygame – jonrsharpe
無法得到它的工作 – user3100799