Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 类型错误:';模块';对象在pygame中不可调用_Python_Python 3.x_Pygame - Fatal编程技术网

Python 类型错误:';模块';对象在pygame中不可调用

Python 类型错误:';模块';对象在pygame中不可调用,python,python-3.x,pygame,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, 4

我是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
回溯(最近一次呼叫最后一次):
文件“C:/Users/ziyaa/PycharmProjects/pygame/helloworld.py”,第13行,在
mouse\u cursor=pygame.image(mouse\u image\u文件名).convert\u alpha()
TypeError:“模块”对象不可调用
进程已完成,退出代码为1
您正在做:

background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
在第二条指令中,您忘记加载映像,导致调用模块而不是函数

只要做:

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

您的问题是for 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)) 

需要无凹痕或向后移动

第一篇文章和完整的stacktrace包括在内:这口井应该得到一次向上投票,并得到一个答案:)正如有人指出的,你的缩进最后有点不对劲。你可能会遇到问题(但这与问题无关,我会将其编辑掉)这不是问题,但这可能是下一个问题。那是因为你有英语背景。没有加载如何?崩溃没有显示?图像在哪里?