Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 TypeError:“pygame.Surface”对象不可调用,pygame窗口崩溃_Python_Crash_Pygame - Fatal编程技术网

Python TypeError:“pygame.Surface”对象不可调用,pygame窗口崩溃

Python TypeError:“pygame.Surface”对象不可调用,pygame窗口崩溃,python,crash,pygame,Python,Crash,Pygame,我对Pygame和Python非常陌生,我刚刚编写了我的第一个代码之一,但不知怎的,我一直遇到这样的错误: TypeError: 'pygame.Surface' object is not callable 我不知道代码中是否有错误,或者仅仅因为Pygame/Python没有正确安装 bif="bg.jpg" mif="ball.png" import pygame, sys from pygame.locals import * pygame.init() screen=pygame.

我对Pygame和Python非常陌生,我刚刚编写了我的第一个代码之一,但不知怎的,我一直遇到这样的错误:

TypeError: 'pygame.Surface' object is not callable
我不知道代码中是否有错误,或者仅仅因为Pygame/Python没有正确安装

bif="bg.jpg"
mif="ball.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((640,360),0,32)

background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()

while True:
   for event in pygame.event.get():
     if event.type == QUIT:
        pygame.quit()
        sys.exit()

screen.blit(background, (0,0))

x,y = pygame.mouse.get_pos()
x -= mouse_c.get_width()/2
y -= mouse_c.get_height()/2

screen.blit(mouse_c(x,y))

pygame.display.update()

运行此代码后,pygame窗口崩溃。

您缺少一个逗号:

screen.blit(mouse_c(x,y))
应该是

screen.blit(mouse_c, (x,y))
                 # ^

在第一个版本中,mouse_cx,y被解释为试图调用mouse_c,这是一个pygame.Surface,因此不能使用参数x和y调用,因为它们实际上是独立的参数source和dest to。

缺少逗号:

screen.blit(mouse_c(x,y))
应该是

screen.blit(mouse_c, (x,y))
                 # ^

在第一个版本中,mouse_cx,y被解释为试图调用mouse_c,这是一个pygame.Surface,因此不能使用参数x和y调用,因为它们实际上是独立的参数source和dest to。

我不熟悉pygame,但错误是不言自明的。在代码的某个地方,您得到了一个pygame.Surface类型的对象,然后您试图使用操作符调用它。我猜你认为是方法的东西实际上只是一个属性值,因此不需要。你能提供完整的回溯吗?回溯最近的调用:File/Users/dhti/Desktop/gamez/game.py,第27行,在screen.blitmouse_cx中,y TypeError:“pygame.Surface”对象不可调用@jornsharpei我不熟悉pygame,但错误是不言自明的。在代码的某个地方,您得到了一个pygame.Surface类型的对象,然后您试图使用操作符调用它。我猜你认为是方法的东西实际上只是一个属性值,因此不需要。你能提供完整的回溯吗?回溯最近的调用:File/Users/dhti/Desktop/gamez/game.py,第27行,在screen.blitmouse_cx,y TypeError:“pygame.Surface”对象不可调用@jornsharpe