DEV Community

Guyzie754
Guyzie754

Posted on

pygame button gui

    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(watercycle, CYAN, (x, y, w, h))
            if (click[0] == 1 and action != None):
                if  (action == "Start"):
                    game_loop()
                elif  (action == "Load"):
                    ##Function that makes the loading of the saved file##
                elif  (action == "Exit"):
                    pygame.quit()

        else:
            pygame.draw.rect(watercycle, BLUE, (x, y, w, h))
            smallText = pygame.font.Font("freesansbold.ttf", 20)
            textSurf, textRect = text_objects(msg, smallText)
            textRect.center = ( (x+(w/2)), (y+(h/2)) )
            watercycle.blit(textSurf, textRect)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)