0

When I press escape it show the button but I can't click on it and it doesn't change his color. I try to quit the game with the button but it seems that I couldn't. This is the code:

import pygame
import pygame.locals

pygame.init()

screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

white = (255,255,255)

light_button = (170,170,170)

dark_button = (100,100,100)

width = screen.get_width()

height = screen.get_height()

smallfont = pygame.font.SysFont('Corbel',35)


text = smallfont.render('QUIT' , True , white)


while True:


    for ev in pygame.event.get():
        pygame.display.update()

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


        #regarde si echap est cliqué
        if ev.type == pygame.locals.KEYDOWN and ev.key == pygame.K_ESCAPE:
            screen.fill((60,25,60))

           # stoque la position de la souris dans un tuple
            mouse = pygame.mouse.get_pos()
            pygame.display.update()

           #si la souris passe sur le bouton il change de couleur
            if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
                pygame.draw.rect(screen,light_button,[width/2,height/2,140,40])
                pygame.display.update()

            else:
                pygame.draw.rect(screen,dark_button,[width/2,height/2,140,40])
                pygame.display.update()

            #superpose le texte sur le bouton
            screen.blit(text , (width/2+50,height/2))
            pygame.display.update()

            #regarde si la souris est cliquée
            if ev.type == pygame.MOUSEBUTTONDOWN:
                pygame.display.update()

                if width/2 <= mouse[0] <= width/2+140 and height/2 <= mouse[1] <= height/2+40:
                    pygame.quit()
                    pygame.display.update()

#actualise les frames
pygame.display.update()
matszwecja
  • 6,357
  • 2
  • 10
  • 17

0 Answers0