TypeError:'模块'对象在pygame中不可调用

时间:2017-01-14 22:31:41

标签: python python-3.x pygame

我是pygame的新手,我有这个错误,请帮助我。

    backgrounf_image_filename = 'ubisoft.jpg'
    mouse_image_filename = 'cursor.png'

    import pygame
    from pygame.locals import *
    from sys import exit

    pygame.init()

    screen = pygame.display.set_mode((640, 480), 0, 32)
    pygame.display.set_caption("Hello World!")
    background = pygame.image.load(backgrounf_image_filename).convert()
    mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()

我有这个错误:

    Traceback (most recent call last):
      File "C:/Users/ziyaa/PycharmProjects/pygame/helloworld.py", line 13, in <module>
        mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
    TypeError: 'module' object is not callable

    Process finished with exit code 1

2 个答案:

答案 0 :(得分:0)

你在做:

background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()

在第二条指令中,您忘记了load您的图片,导致调用模块而不是函数。

只是做:

mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()

答案 1 :(得分:0)

你的问题是你的event.get循环。我在我的游戏中使用了类似的游戏,但是正确的方法却让你的下几行缩进错误

x, y = pygame.mouse.get_pos()
        x -= mouse_cursor.get_width()/2
        y -= mouse_cursor.get_height()/2
        screen.blit(mouse_cursor, (x, y)) 

需要不受欢迎或退回