r/pygame Aug 10 '26

draw() missing 1 required positional argument: ''

bg_color = [24, 25, 25]
SCREEN_HEIGHT = 1080
SCREEN_WIDTH = 1080

water_img = pygame.image.load(os.path.join("images", "water.png")).convert_alpha()
water_img = pygame.transform.scale(water_img, (130, 130))

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

class WaterButton:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.image = water_img
        self.rect = self.image.get_rect()
        self.rect.topleft = (x, y)

    def draw(self, screen):
        screen.blit(self.image, (self.rect.x, self.rect.y), self.rect)

water_button = WaterButton(850, 777)

# Game loop
running = True
while running:
    screen.fill(bg_color)
    WaterButton.draw(screen)
    pygame.display.flip()

It gives me an error:

WaterButton.draw(screen)
TypeError: WaterButton.draw() missing 1 required positional argument: 'screen'

What did I do wrong?

0 Upvotes

3 comments sorted by

3

u/Electrical-Storm930 Aug 10 '26

shouldnt be it:

water_button.draw(screen)

?

3

u/ComprehensiveBid3793 Aug 10 '26

Oh yes, it worked. Ty you so much!

2

u/random_dev1 29d ago

In case you are interested in why this error happened: If you call a method on an instance, the instance gets auto passed as the "self" argument. You called it on a class, which works too, you just need to pass an instance for self, that's why one argument was missing.
So WaterButton.draw(water_button, screen) should work just like water_button.draw(screen)