纯小白,跟着蟒蛇书学python,但这一段一直提示pygame.error:video system not initialized。检查了好几遍不知道哪出了问题。python版本:3.8
import sys
import pygame
class AlienInvasion:
"""管理游戏资源和行为的类"""
def _init_(self):
"""初始化游戏并创建游戏资源"""
pygame.init()
self.screen = pygame.display.set_mode((2400,1600))
pygame.display.set_caption("Alien Invasion")
def run_game(self):
"""开始游戏主循环"""
while True:
#监视键盘和鼠标事件。
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#让最近绘制的屏幕可见。
pygame.display.flip()
ai = AlienInvasion()
ai.run_game()
注意初始化函数__init__前后各有两个下划线