184 Chapter 8
In this case, we’ve told blit() that we want to draw pic at the loca-
tion (100,100), or right 100 pixels and down 100 pixels from the
upper-left corner of the screen (in Pygame’s coordinate system, the
origin is the upper-left corner; see Figure 8 -3 on page 180).
The final line of our game loop is the call to pygame.display
.update(). This command tells Pygame to show the drawing win-
dow with all the changes that have been made during this pass
through the loop. That includes our smiley face. When update()
runs, the window will be updated to show all the changes to our
screen surface.
So far, we’ve taken care of our setup code, and we have a game
loop with an event handler that listens for the user hitting the
close window button. If the user clicks the close window button, the
program updates the display and exits the loop. Next, we’ll take care
of ending the program.
e iting the Programx
The last section of our code will exit the program once the user has
chosen to quit the game loop:
pygame.quit() # Exit
If you leave this line out of your programs, the display window
will stay open even after the user tries to close it. Calling pygame
.quit() closes the display window and frees up the memory that
was storing our image, pic.
Putting it all Together
Put it all together, and you’ll see our CrazySmile.bmp image file—
as long as you’ve saved the image in the same directory as your
ShowPic.py program file. Here’s the full listing:
ShowPic.py
import pygame # Setup
pygame.init()
screen = pygame.display.set_mode([800,600])
keep_going = True
pic = pygame.image.load("CrazySmile.bmp")