Adding event handling help us exit from application by clicking close button or pressing some other button.
for event in pygame.event.get():
if event.type == pygame.QUIT:
runing = False
Now you can exit from application by clicking close button.
Event types
There are defined other event types pygame.(KEYUP, KEYDOWN, MOUSEMOTION, MOUSEBUTTONP, MOUSEBUTTONDOWN, VIDEORESIZE). All of these events described in pygame documentation
Tutorial source