Python 我正在制作一个使用箭头键导航的菜单,但它不起作用

Python 我正在制作一个使用箭头键导航的菜单,但它不起作用,python,pygame,Python,Pygame,我正在制作一个使用左右箭头键导航的菜单游戏。问题是,当您按下其中一个箭头时,它会在两个箭头之间快速切换。我假设我需要使用pygame.KEYUP,但我不确定如何使用它。现在,它只是在播放和退出之间闪烁。这是我的密码。我想要这样,如果你按左键或右键,它会选择播放或退出,并且不会在两者之间闪烁 ''' Mega Maro Bois Zan3yGameZ 2018 ''' import pygame, time pygame.init() def createWindow(): glo

我正在制作一个使用左右箭头键导航的菜单游戏。问题是,当您按下其中一个箭头时,它会在两个箭头之间快速切换。我假设我需要使用
pygame.KEYUP
,但我不确定如何使用它。现在,它只是在播放和退出之间闪烁。这是我的密码。我想要这样,如果你按左键或右键,它会选择播放或退出,并且不会在两者之间闪烁

'''
Mega Maro Bois

Zan3yGameZ 2018
'''

import pygame, time

pygame.init()

def createWindow():
    global WIDTH, HEIGHT, TITLE, W
    WIDTH, HEIGHT = 800, 450
    TITLE = "Mega Maro Bois"
    pygame.display.set_caption(TITLE)
    W = pygame.display.set_mode( (WIDTH, HEIGHT), pygame.HWSURFACE|pygame.DOUBLEBUF )

createWindow()


menu = pygame.image.load("Graphics\\Menu.png")
############################################################# PLAY PICTURES
play = pygame.image.load("Graphics\\Play.png")
play_sel = pygame.image.load("Graphics\\Play_Selected.png")
############################################################# QUIT PICTURES
quit = pygame.image.load("Graphics\\Quit.png")
quit_sel = pygame.image.load("Graphics\\Quit_Selected.png")


Event = "Menu"

loop = True

Button_Sel = "Play"
Button_Sel2 = 1


if Event == "Menu":
    W.blit(menu, (0, 0))
    W.blit(play, (25, 250))
    W.blit(quit, (435, 250))

while loop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()

    if Event == "Menu":

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_1:
                Button_Sel = "Play"
            if event.key == pygame.K_2:
                Button_Sel = "Quit"
            if event.key == pygame.K_RIGHT:
                Button_Sel2 += 1
            if event.key == pygame.K_LEFT:
                Button_Sel2 -= 1


            #################################################################ENTER SELECT
            if Button_Sel == "Play" and event.key == pygame.K_RETURN:
                Event = "Play"
            if Button_Sel == "Quit" and event.key == pygame.K_RETURN:
                pygame.quit()
                exit()
            #################################################################SPACE SELECT
            if Button_Sel == "Play" and event.key == pygame.K_SPACE:
                Event = "Play"
            if Button_Sel == "Quit" and event.key == pygame.K_SPACE:
                pygame.quit()
                exit()                      


        ###################################################IF USER SELECTS PLAY
        if Button_Sel == "Play":
            W.blit(play_sel, (25, 250))
            W.blit(quit, (435, 250))
        ###################################################IF USER SELECTS QUIT
        if Button_Sel == "Quit":
            W.blit(play, (25, 250))
            W.blit(quit_sel, (435, 250))

        if Button_Sel2 == 1:
            Button_Sel = "Play"
        if Button_Sel2 == 2:
            Button_Sel = "Quit"


    pygame.display.update()

pygame.quit()
exit()

我主要需要知道如何在这种情况下使用
pygame.KEYUP

如果event.type==pygame.KEYDOWN:在pygame.event.get()中的event的事件处理循环
之外:

这意味着你不断地重复处理同一事件


将事件检查放入循环中。

问题已经回答,也许您应该用更新的代码问另一个问题。我刚刚取消了按1和2的功能,感谢da的帮助