Pygame 1-2 Lessons
Pygame 1-2 Lessons
Notice that we pass a tuple value of two integers to the function: (400, 300). This tuple
tells the set_mode() function how wide and how high to make the window in pixels.
(400, 300) will make a window with a width of 400 pixels and height of 300 pixels.
Line 6 sets the caption text that will appear at the top of the window by calling the
pygame.display.set_caption() function.
If the user clicked the mouse and then pressed a keyboard key, the Event object for
the mouse click would be the first item in the list and the Event object for the
keyboard press would be second.
Line 9 checks if the Event object’s type is equal to the constant QUIT. Remember
that since we used the from pygame.locals import * form of the import statement,
we only have to type QUIT instead of pygame.locals.QUIT.
If the Event object is a quit event, then the pygame.quit() and sys.exit() functions are
called. The pygame.quit() function is sort of the opposite of the
pygame.init()function: it runs code that deactivates the Pygame library. Your
programs should always call
pygame.quit() before they call sys.exit() to terminate the program.
Line 12 calls the pygame.display.update() function, which draws the
Surface object returned by pygame.display.set_mode() to the screen
(remember we stored this object in the DISPLAYSURF variable).