GuiLLaume
GuiLLaume

Reputation: 11

Error: 'pygame.Surface' object is not callable

Good day ! I'm creating a program for the end of school year. But the famous problem of " 'pygame.Surface' object is not callable" is come. I don't now where is the mistake. The program :

def Setfenetre():

    #New window
    fenetre= pygame.display.set_mode((800, 464), FULLSCREEN)
    background=pygame.image.load("Ressources/Images/Set_window4.jpg").convert()
    fenetre.blit(background, (0,0))
    pygame.display.flip()

    #BoutonSOUND(ON/OFF)
    SOUND_area = pygame.Rect((280,55), (250,50))
    rect_surf = pygame.Surface(SOUND_area.size)
    rect_surf.set_alpha(0)

    #BoutonRETURN
    RETURN_area = pygame.Rect((315,165), (171,45))
    rect_surf = pygame.Surface(RETURN_area.size)
    rect_surf.set_alpha(0)

    #Son clic:
    soundClic= pygame.mixer.Sound("Ressources/Sons/Clic.wav")

    #SonON/OFF / Sorti de Setfenetre
    jeu=1
    while jeu:
        for event in pygame.event.get():
            if event.type == MOUSEBUTTONDOWN:
                if  SOUND_area.collidepoint(event.pos) or RETURN_area.collidepoint(event.pos):
                    if event.button== 1:
                        soundClic.play()
                if SOUND_area.collidepoint(event.pos):
                    if event.button== 1:
                        soundMainMenu.stop()
                if RETURN_area.collidepoint(event.pos):
                    if event.button== 1:
                        jeu=0
                        fenetre("MainMenu")
        fenetre.blit(rect_surf, RETURN_area)
        pygame.display.flip()
    pygame.quit()

Python tells me this error : (TypeError: 'pygame.Surface' object is not callable) PS : My pygame window is not init. because it is does in an other fonction named "fenetre()".

Thank you very much for your answer !

Upvotes: 1

Views: 176

Answers (1)

Rabbid76
Rabbid76

Reputation: 211277

You have to use a different name, either for the fenetre function or for the local instance of the fenetre Surface. The Surface (fenetre= pygame.display.set_mode(...)) "shadows" the function, because they have the same name.
Change the name of the display Surface variabel and each use of it:

fenetre= pygame.display.set_mode((800, 464), FULLSCREEN)

fenetre_surf = pygame.display.set_mode((800, 464), FULLSCREEN)

Upvotes: 1

Related Questions