Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: draw_shape() missing 1 required positional argument: 'self'

i’m trying to code a simple game of pong as a way to learn pygame as i’m not that experienced in coding. I’ve only recently started to use classes and i guess i don’t quite understand how to use init properly As whenever i run the code:


class ball:

    def __init__(self):
        self.y = y
        
    def draw_shape(self):
        
        pygame.draw.circle(screen, WHITE,(30 , self.y),15)
        pygame.display.flip()


while running:
    clock.tick(fps)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == KEYDOWN and (event.key == K_UP):
            player.y = player.y + vel
    screen.fill(BLACK)
    visual.border_draw()
    visual.mid_lines()
    visual.score()
    ball.draw_shape()

i get the error message:

TypeError: draw_shape() missing 1 required positional argument: 'self'

any help is appreciated 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try:

ball().draw_shape()

or just

player = ball()
player.draw_shape()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading