关于#pygame#无窗口弹出的问题,如何解决?

import sys
import pygame


class AlienInvasion:  # 管理 资源与类 的类
    def _init_(self):
        pygame.init()

        self.screen = pygame.display.set_mode((1200, 800))
        pygame.display.set_caption("Alien Invasion")
        # self.bg_color = (230, 230, 230)

    def run_game(self):  # 开始游戏主循环
        while True:
            # supervise keyboard and mouse item
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
            # visualiaze the window
            pygame.display.flip()


if __name__ == ' _main_':
    # 创建并运行游戏
    ai = AlienInvasion()
    ai.run_game()

类的初始化函数是左右各两个下划线:

def __init__(self):

还有主程序的名字main也是左右各两个下划线

if __name__ == '__main__':
这篇文章:pygame 窗口标题和图标设置 也许有你想要的答案,你可以看看