pygame.click.get_pressed()返回3个值。为什么会这样

时间:2019-06-10 15:07:30

标签: python python-3.x pygame

我创建了3个名为“ rock”,“ paper”,“ scissors”的按钮,我们按下其中任意一个按钮,它将返回3个值,即运行3次。请帮我解决一下这个。例如。当我按下摇滚按钮时,摇滚会被打印三次。

def button(msg, x, y, w, h, ic, ac, action=None):

    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x + w > mouse[0] > x and y + h > mouse[1] > y:

        pygame.draw.rect(screen, ac, (x, y, w, h))

        if click[0] == 1 and action != None:

            if action == 'rock':
                print('rock')

            elif action == 'paper':
                print('paper')

            elif action == 'scissor':
                print('scissors')

    else:

        pygame.draw.rect(screen, ic, (x, y, w, h))

    text = pygame.font.Font("freesansbold.ttf", 15)
    textSu, textRe = text_obj(msg, text) #text_obj() gives the font n others things
    textRe.center = ((x + (w / 2), (y + (h / 2))))
    screen.blit(textSu, textRe)

0 个答案:

没有答案