简体   繁体   English

类型错误:参数 1 必须是 pygame.Surface,而不是类型

[英]TypeError: argument 1 must be pygame.Surface, not type

I'm making a submarine game in python, but when I try to run it, the interpreter gives me very strange error: "TypeError: argument 1 must be pygame.Surface, not type."我正在用 python 制作潜艇游戏,但是当我尝试运行它时,解释器给了我一个非常奇怪的错误:“TypeError:参数 1 必须是 pygame.Surface,而不是类型。” I tried to search the web for my answer, but it seems like this isn't very usual error.我试图在网上搜索我的答案,但这似乎不是很常见的错误。 I also tried to find error by myself, but everything seemed fine to me.我也试图自己找出错误,但对我来说一切都很好。 Here 's part of the code that I think error is in:这是我认为错误所在的代码的一部分:

mina = pygame.image.load('mina.png')
class mina():
    def __init__(self, x , y):
        self.x = x
        self.y = y
        self.eksplozija = False
    def naris(self):
        screen.blit(mina, (self.x, self.y))
igralec = podmornica(150, 300, 10)
eksploziv = mina(700, 350)
metki = []
clock = pygame.time.Clock()
def grafika():
    clock.tick(60)
    screen.blit(ozadje, (0,0))
    igralec.naris()
    #line, that doesn't work:
    eksploziv.naris()
    for metek in metki:
        metek.naris(screen)
    pygame.display.flip()

The variable mina and the class mina have the same name.变量mina和类mina具有相同的名称。 The class mina shadows the variable mina . minamina了变量mina You need to rename one or the other.您需要重命名其中一个。 I recommend to rename the calss mina to Mina , since Python classes use the CapWords convention ( PEP 8 -- Style Guide for Python Code ):我建议将 calss mina重命名为Mina ,因为 Python 类使用 CapWords 约定( PEP 8 -- Python 代码风格指南):

class mina():

class Mina():

eksploziv = mina(700, 350)

eksploziv = Mina(700, 350)

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

相关问题 TypeError:参数1必须是pygame.Surface,而不是str - TypeError: argument 1 must be pygame.Surface, not str TypeError:参数1必须是pygame.Surface,而不是方法 - TypeError: argument 1 must be pygame.Surface, not method TypeError:参数1必须是pygame.Surface,而不是pygame.Rect - TypeError: argument 1 must be pygame.Surface, not pygame.Rect TypeError:参数1必须是pygame.Surface,而不是str [使用按钮的Pygame] - TypeError: argument 1 must be pygame.Surface, not str [Pygame using buttons] Pygame 错误“类型错误:参数 1 必须是 pygame.Surface,而不是列表” - Pygame error 'TypeError: argument 1 must be pygame.Surface, not list' TypeError:参数1必须是pygame.Surface,而不是buildin_function_or_method - TypeError: argument 1 must be pygame.Surface, not builtin_function_or_method 类型错误:参数 1 必须是 pygame.Surface,而不是列表及更多 - TypeError: argument 1 must be pygame.Surface, not list & more “类型错误:参数 1 必须是 pygame.Surface,而不是列表”:不理解 - ' TypeError: argument 1 must be pygame.Surface, not list ' : Not understanding 类型错误:参数 1 必须是 pygame.Surface,而不是列表 - 它不是列表 - TypeError: argument 1 must be pygame.Surface, not list - Its not a list Pygame 参数 2 必须是 pygame.surface 而不是 str - Pygame argument 2 must be pygame.surface not str
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM