-1

pygame を使用して作成されたゲーム用に Python で小さなテキスト クラスを作成しましたが、何らかの理由で既定の引数が機能しません。Pythonのドキュメントを見て、何が間違っていたのかを理解できるかどうかを確認しようとしましたが、ドキュメントの言語を完全には理解していませんでした. 他の誰もこの問題を抱えていないようです。

テキスト クラスのコードは次のとおりです。

class Text:
    def __init__(self,screen,x_location='center',y_location='center',writeable,color,size=12):
        self.font = pygame.font.Font("Milleni Gem.ttf", size)

        self.text = self.font.render(writeable,True,color)
        self.textRect = self.text.get_rect()

        if x_location == "center":
            self.textRect.centerx = screen.get_rect().centerx
        else:
            self.textRect.x = x_location

        if y_location == "center":
            self.textRect.centery = screen.get_rect().centery
        else:
            self.textRect.y = y_location
        self.update()

    def update(self):
        screen.blit(self.text,self.textRect)

これを呼び出すコードは次のとおりです。

from gui import *
Text(screen,75,75,currentweapon.clip)#currentweapon.clip is an integer

私が得るエラーはこれです:

SyntaxError: non-default argument follows default argument

コード内の行を指しdef __init__()ます。このエラーは何を意味し、ここで何が間違っていますか?

4

1 に答える 1

5
def __init__(self,screen,x_location='center',y_location='center',writeable,color,size=12):

デフォルト引数の後にデフォルト以外の引数を定義しました。これは許可されていません。以下を使用する必要があります。

def __init__(self,screen,writeable,color,x_location='center',y_location='center',size=12):
于 2013-07-27T03:04:11.873 に答える