For example, I have a 50 by 50 rectangle and I want to make it so when I press on it with my left mouse key, the program logs or senses that this has happened.
Asked
Active
Viewed 749 times
1 Answers
0
There are two ways you can go about this either:
- call a function every frame and check if the mouse is clicked and within the boundaries of the rectangle in question, you can find an example of this here: https://pythonprogramming.net/pygame-button-function-events/
Or
- check for the event of the mouse button being pressed down or being let go and then check the boundary condition (for it being within the rectangle) , you can use the examples here for reference: https://lorenzod8n.wordpress.com/2007/05/30/pygame-tutorial-3-mouse-events/ , specifically the ones related to mouse buttons
You can check here for a general list of functions for getting the current state of the cursor/mouse: https://www.pygame.org/docs/ref/mouse.html

Griffinhand
- 16
- 3