0

Can any python experts tell me why this is showing this error: win.blit(text_surface, (self.x, + self.width/2 - text_surface.get_width()/2, self.y + self.height/2 - text_surface.get_height()/2)) TypeError: invalid destination position for blit

class Button:
    def __init__(self, x, y, width, height, color, text=None, text_color=BLACK):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.color = color
        self.text = text
        self.text_color = text_color

    def draw(self, win):
        pygame.draw.rect(win, self.color, (self.x, self.y, self.width, self.height))
        pygame.draw.rect(win, BLACK, (self.x, self.y, self.width, self.height), 2)


        if self.text:
            button_font = get_font(22)
            text_surface = button_font.render(self.text, 1, self.text_color)
            win.blit(text_surface, (self.x, + self.width/2 - text_surface.get_width()/2, self.y + self.height/2 - text_surface.get_height()/2))

    def clicked(self, pos):
        
        x, y = pos

        if not (x >= self.x and x <= self.width + self.x):
            return False
        if not (y >= self.y and y<= self.y + self.height):
            return False

        return True
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Rookie519
  • 11
  • 2

0 Answers0