AttributeError: ‘NoneType’ object has no attribute ‘fill’
Traceback (most recent call last):
File “C:\Users\Administrator\PycharmProjects\pythonProject3\tank02.py”, line 148, in
mainGame.startGame()
File “C:\Users\Administrator\PycharmProjects\pythonProject3\tank02.py”, line 43, in startGame
MainGame.window.fill(BG_COLOR)
AttributeError: ‘NoneType’ object has no attribute ‘fill’
Process finished with exit code 1
很久没写代码了,忘的差不多了。今天以为上面的问题是解决不了了。结果经过一步步排查,结果是由于粗心导致的。
pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])
看到这段代码了吗?由于当前窗口是类对象,所以在调用时类名来接收当前窗口的对象,所以pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])要加上MainGame.window=pygame.display.set_mode([SCREEN_WIDTH,SCREEN_HEIGHT])
发布评论