how to get a mouse press not hold in pygame 1

how to get a mouse press not hold in pygame

class Button(object):
    def __init__(self,x,y,width,height,color):
        self.rect = pygame.Rect(x,y,width,height)
        self.image=pygame.draw.rect(screen, color,(self.rect),)

    def check(self):
        return self.rect.collidepoint(pygame.mouse.get_pos())

Here is what the above code is Doing:
1. It creates a class called Button.
2. It creates a constructor for the class.
3. It creates a method called check.

The constructor is a special method that is called when you create an object.
The constructor is called __init__.

The constructor takes 5 parameters:
1. self
2. x
3. y
4. width
5. height

The constructor creates a rectangle using the parameters.
The constructor creates an image using the rectangle.
The constructor creates 5 attributes:
1. rect
2. image
3. x
4. y
5. width
6. height

The check method takes 1 parameter:
1. self

The check method returns True if the mouse is over the button.

Similar Posts