繁体   English   中英

错误:'pygame.Surface' object 不可调用

[英]Error: 'pygame.Surface' object is not callable

再会。 我正在为学年结束创建一个程序。 但是著名的“'pygame.Surface' object is not callable”问题来了。 我现在不知道错误在哪里:程序:

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. 因为它是在另一个名为“fenetre()”的函数中完成的。

非常感谢您的回答 !

您必须为fenetre function 或fenetre Surface的本地实例使用不同的名称。 Surface (fenetre= pygame.display.set_mode(...)) “遮蔽”了 function,因为它们具有相同的名称。
更改显示表面变量的名称及其每次使用:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM