Untitled

mail@pastecode.io avatar
unknown
python
22 days ago
1.3 kB
1
Indexable
Never
class Button():
    def __init__(self, image, hover, textINP, font, colour, pos):
        self.image = image
        self.x_pos = pos[0]
        self.y_pos = pos[1]
        self.font = font
        self.colour, self.hover = colour, hover
        self.textINP = textINP
        self.text = self.font.render(self.textINP, True, self.colour)
        if self.image == None:
            self.image = self.text
        self.rect = self.image.get_rect(center=(self.x_pos, self.y_pos))
        self.text_rect = self.text.get_rect(center=(self.x_pos, self.y_pos))

    def update(self, screen):
        if self.image is not None:
            screen.blit(self.image, self.rect)
        screen.blit(self.text, self.text_rect)

    def input_check(self, position):
        if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
            return True
        return False
    
    def colourChange(self, position):
        if position[0] in range(self.rect.left, self.rect.right) and position[1] in range(self.rect.top, self.rect.bottom):
            self.text = self.font.render(self.textINP, True, self.hover)
        else:
            self.text = self.font.render(self.textINP, True, self.colour)
Leave a Comment