Python 退出游戏无法正常工作

Python 退出游戏无法正常工作,python,pygame,Python,Pygame,在这种情况下,我希望程序在按下退出按钮时关闭,但如果启用我的Check\u Key\u Press()函数,则close()函数不起作用,但是如果我注释掉Check\u Key\u Press()函数,它会再次起作用 import pygame pygame.init() width, height = 500,500 win = pygame.display.set_mode((width, height)) pygame.display.set_caption("Tic Tac

在这种情况下,我希望程序在按下退出按钮时关闭,但如果启用我的
Check\u Key\u Press()
函数,则
close()
函数不起作用,但是如果我注释掉
Check\u Key\u Press()
函数,它会再次起作用

import pygame

pygame.init()
width, height = 500,500
win = pygame.display.set_mode((width, height))
pygame.display.set_caption("Tic Tac Toe(GUI)")
clock = pygame.time.Clock()

white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)

Tile_dime = 59
Diff = (Tile_dime+1)/2
board_det = [['-',(width/2-3*Diff,height/2-3*Diff)],['-',(width/2-Diff,height/2-3*Diff)],['-',(width/2+Diff,height/2-3*Diff)],
            ['-',(width/2-3*Diff,height/2-Diff)],['-',(width/2-Diff,height/2-Diff)],['-',(width/2+Diff,height/2-Diff)],
            ['-',(width/2-3*Diff,height/2+Diff)],['-',(width/2-Diff,height/2+Diff)],['-',(width/2+Diff,height/2+Diff)]]

def draw_board():
    for i in range(len(board_det)):
        pygame.draw.rect(win, white, [board_det[i][1], (Tile_dime, Tile_dime)])

def Close():
    global run
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

def Check_Key_Press():
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            pass
            if event.key == pygame.K_LEFT:
                pass

run = True
while run:
    clock.tick(60)
    draw_board()
    Check_Key_Press()
    Close()
    pygame.display.update()
获取所有消息并将其从队列中删除。如果在多个事件循环中调用
pygame.event.get()
,则只有一个循环接收事件,但并非所有循环都接收所有事件。因此,一些活动似乎被错过了

获取一次事件并在多个循环中使用它们,或者将列表或事件传递给处理它们的函数和方法:

def关闭(事件列表):
全球运行
对于事件列表中的事件:
如果event.type==pygame.QUIT:
运行=错误
def检查键按下(事件列表):
对于事件列表中的事件:
如果event.type==pygame.KEYDOWN:
通过
如果event.key==pygame.K_左:
通过
run=True
运行时:
时钟滴答(60)
event_list=pygame.event.get()
绘图板()
检查按键(事件列表)
关闭(事件列表)
pygame.display.update()