按钮在那里,但不显示。仅在光标悬停在鼠标上时显示它们

时间:2019-05-30 13:34:36

标签: python python-3.x pygame

我正在尝试在pygame,python中对游戏-Rock Paper Scissors进行编程。程序成功运行,但显示保持空白。仅当光标悬停在按钮位置时,按钮才会出现。我已经尝试了一切,但没有结果。请帮助我。

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

    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:

            if action == 'rock':
                rock(x, y)

            elif action == 'paper':
                paper(x, y)

            elif action == 'scissor':
                scissors(x, y)
        text = pygame.font.Font("freesansbold.ttf", 15)
        textSu, textRe = text_obj(msg, text)
        textRe.center = ((x + (w / 2), (y + (h / 2))))
        screen.blit(textSu, textRe)


def game()

        while hi:

        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        button("Rock", 1, 1, 100, 25, red, 'rock')
        button("paper", 5, 50, 100, 25, green, 'paper')
        button("scissor", 10, 100, 100, 25, blue, 'scissor')


pygame.quit()

0 个答案:

没有答案