小编4ur*_*y0n的帖子

使用 Pygame 创建矩形按钮

我正在尝试rect在 Pygame 中使用按钮。我从红色的退出按钮开始,并检查点击是否在按钮的边界框内。

    import pygame
"""import nemesis.py;"""

pygame.init();
screen = pygame.display.set_mode((400,300));
pygame.display.set_caption("menu");
menuAtivo = True;

start_button = pygame.draw.rect(screen,(0,0,240),(150,90,100,50));
continue_button = pygame.draw.rect(screen,(0,244,0),(150,160,100,50));
quit_button = pygame.draw.rect(screen,(244,0,0),(150,230,100,50));


pygame.display.flip();


while menuAtivo:
    for evento in pygame.event.get():
        print(evento);
        if evento.type == pygame.MOUSEBUTTONDOWN:
            if pygame.mouse.get_pos() >= (150,230):
                if pygame.mouse.get_pos() <= (250,280):
                        pygame.quit();
                    
Run Code Online (Sandbox Code Playgroud)

python pygame button

3
推荐指数
2
解决办法
2万
查看次数

标签 统计

button ×1

pygame ×1

python ×1