Skip to main content
Engineering LibreTexts

6.8: Checking for Mouse Clicks

  • Page ID
    14538
  •         checkForQuit()
            for event in pygame.event.get(): # event handling loop
                if event.type == MOUSEBUTTONUP:
                    mousex, mousey = event.pos
                    clickedButton = getButtonClicked(mousex, mousey)
    

    Line 1 [80] does a quick check for any QUIT events, and then line 2 [81] is the start of the event handling loop. The XY coordinates of any mouse clicks will be stored in the mousex and mousey variables. If the mouse click was over one of the four buttons, then our getButtonClicked() function will return a Color object of the button clicked (otherwise it returns None).

    • Was this article helpful?