Skip to main content
Engineering LibreTexts

9.6: The main() Function

  • Page ID
    13616
  • def main():
        global FPSCLOCK, DISPLAYSURF, BASICFONT, L_SQUIR_IMG, R_SQUIR_IMG, GRASSIMAGES
    
        pygame.init()
        FPSCLOCK = pygame.time.Clock()
        pygame.display.set_icon(pygame.image.load('gameicon.png'))
        DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT))
        pygame.display.set_caption('Squirrel Eat Squirrel')
        BASICFONT = pygame.font.Font('freesansbold.ttf', 32)
    

    The first several lines of the main() function are the same setup code that we’ve seen in our previous game programs. The pygame.display.set_icon() is a Pygame function that sets the icon in the window’s title bar (just like pygame.display.set_caption() sets the caption text in the title bar). The single argument to pygame.display.set_icon() is a Surface object of a small image. The ideal image size is 32 x 32 pixels, although you can use other sized images. The image will just be compressed into a smaller size to be used as the window’s icon.