FIGURE 23.7 An uncentered photo.
To properly center your images, you need to add an additional variable to the place where the display
screen is set up in your Python script. This variable, called CenterScreen, uses the .center
method on the display screen to find exactly the center point of the current screen. Here’s an example:
Click here to view code image
PrezScreenRect = PrezScreen.get_rect()
CenterScreen = PrezScreenRect.center
Within the display picture for loop, you modify the variable PictureLocation slightly. After
the current location of the picture’s rectangular area is obtained, the center of the picture’s rectangle
is set, using .center method:
Click here to view code image
PictureLocation=Picture.get_rect() #Current location
PictureLocation.center=CenterScreen #Put picture in center of screen
Thus, when the picture is put on the screen using the following code, its center will be exactly the
center of the presentation screen:
Click here to view code image
PrezScreen.blit(Picture,PictureLocation)
How cool is this?!
You have seen lots of bits and pieces of code to produce this presentation script. Listing 23.2 shows
the entire script that has been put together so far.
LISTING 23.2 The script2301.py Presentation Script