What is this error and how to fix it?…. this scale doesnt work

the error it shows TypeError: argument 3 must be pygame.Surface, not int

please help me fix this .
so the line is line 15 and line 21 that causes trouble…

import pygame
pygame.init()
screen = pygame.display.set_mode((3840,2160))
running = True
mouse = pygame.mouse.get_pos()

pygame.display.set_caption("GermanBall")
bg = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\Tan.jpg")
icon = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\box.png")
button1 = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\shirt.png").convert_alpha()
class Button():
    def __init__(self,x,y,image, scale):
        width = image.get_width()
        height = image.get_height()
        self.image = pygame.transform.scale(image, int(width * scale ), int(height * scale))
        self.rect = self.image.get_rect()
        self.rect.topleft = (x,y)

    def draw(self):
        screen.blit(self.image,(self.rect.x,self.rect.y)) 
start = Button(1200,300,button1,0.5)


pygame.display.set_icon(icon)
while running == True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    screen.blit(bg,(0,0))
    start.draw()
    pygame.display.update()


>Solution :

The 2nd argument of pygame.transform.scale() is a tuple with 2 elements hat specify the new size of the image ((x, y) instead of x, y):

self.image = pygame.transform.scale(image, int(width * scale ), int(height * scale))

self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))

Leave a Reply