[英]TypeError: 'module' object is not callable in pygame
I'm new in pygame and I have that error please help me. 我是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()
and I have that error: 我有那个错误:
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
You're doing: 你在做:
background = pygame.image.load(backgrounf_image_filename).convert()
mouse_cursor = pygame.image(mouse_image_filename).convert_alpha()
In the second instruction, you forgot to load
your image, resulting in calling the module instead of the function. 在第二条指令中,您忘记load
图像,从而导致调用模块而不是函数。
Just do: 做就是了:
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
Your problem is your for event.get loop. 您的问题是您的for event.get循环。 I use a similar one for my games, and its the right approach however you have your next few lines indented wrong 我在游戏中使用了类似的方法,但它的方法正确,但是接下来的几行缩进了错误
x, y = pygame.mouse.get_pos()
x -= mouse_cursor.get_width()/2
y -= mouse_cursor.get_height()/2
screen.blit(mouse_cursor, (x, y))
needs to be unidented or moved back 需要不明身份或移回
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.