PyGame Menu Formatting
Question: So I've been recently working on programming a game in Python as well as an
external library called PyGame. If anyone is familiar with the game
Hearthstone, that is sort of the feel I'm going for. However, that is besides
the point. I have already researched how to display images and their
positions, and I have been stuck trying to figure out to create a menu with
buttons in the PyGame UI. I have previously programmed in Visual Basic, and I
was wondering if the PyGame interface allowed for system event detection in
general, not unlike Visual Basic (i.e. mouse clicks, key presses). Help would
be much appreciated. Thanks in advance!


Answer: One needs to make a `while` loop to have event detection in pygame. Here is an
example:

    
    
    import time
    
    while 1:
      for event in pygame.event.get():
        if event.type == pygame.QUIT:
          #happens when 'X' in window is clicked
          #put code to be executed here
        elif event.type == pygame.MOUSEBUTTONDOWN:
          onclick_function(pygame.mouse.get_pos) 
          #passes mouse position as tuple to function to deal with click control.
    

When blitting images to the display, one needs to know coordinates. Simply
keep a list of `Rect` objects, each with a function to execute when they are
clicked, and use a function to iterate through the list and see if the
coordinates of the mouse are inside the `Rect`.

See the links for blitting images to the display:

Links:

-`Rect`: <http://www.pygame.org/docs/ref/rect.html#pygame.Rect>

-`Surface`: <http://www.pygame.org/docs/ref/surface.html#pygame.Surface>

-`image`: <http://www.pygame.org/docs/ref/image.html>

