Skip to main content
Engineering LibreTexts

5.17: Drawing the Buttons

  • Page ID
    14547
  • def drawButtons():
        pygame.draw.rect(DISPLAYSURF, YELLOW, YELLOWRECT)
        pygame.draw.rect(DISPLAYSURF, BLUE,   BLUERECT)
        pygame.draw.rect(DISPLAYSURF, RED,    REDRECT)
        pygame.draw.rect(DISPLAYSURF, GREEN,  GREENRECT)
    

    Since each of the buttons is just a rectangle of a certain color in a certain place, we just make four calls to pygame.draw.rect() to draw the buttons on the display Surface. The Color object and the Rect object we use to position them never change, which is why we stored them in constant variables like YELLOW and YELLOWRECT.