学习python编写游戏代码的时候遇到了一点小问题

学习python编写游戏代码的时候遇到了一点小问题

看python编程从入门到实践这本书的时候,外星人

```
import sys
import pygame
def run_game():
pygame.init()
screen=pygame.display.set_mode((1200,800))
pygame.display.set_caption('Alien Invasion')
while True:
for event in pygame.event.get():
sys.exit()
pygame.display.filp()
run_game()

```入侵项目里有这样一节代码。根据书中提示,应该运行 起来是一个1200像素宽,800像素高的窗口。但是我这边pygame之前有下过了,Python版本是3.8.2对应的pygame2.0.1版本。
运行程序的时候没有报错。Sublime-Text编辑器下方有两行提示:
pygame 2.0.1 (SDL 2.0.14, Python 3.8.2)
Hello from the pygame community.


但是pygame窗口打不开,会闪退。请问怎么解决这个问题呢?

你写错了!

import sys
import pygame
def run_game():
    pygame.init()
    screen=pygame.display.set_mode((1200,800))
    pygame.display.set_caption('Alien Invasion')
    while True:
        for event in pygame.event.get():
            if event.type==pygame.QUIT: 
'''这里你直接就省略了,结果就是一开始就运行了sys.exit,而不是等用户按×按钮'''
                sys.exit()
        pygame.display.filp()
run_game()