Skip to main content
Engineering LibreTexts

6.17: Drawing the Buttons

  • Page ID
  • 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.

    • Was this article helpful?