gpt4 book ai didi

python - 类继承,使用新参数重新定义 __init__ on

转载 作者:太空宇宙 更新时间:2023-11-04 01:39:24 36 4
gpt4 key购买 nike

我是 Python 的新手,我仍然对类继承的语义有疑问。

以下是我正在导入的模块 games.py 模块中的相关类:

class Text(Sprite): 
"""
Alphanumeric values displayed on the screen.
"""
def __init__(self, value, size, color, angle=0,
x=0, y=0,
top=None, bottom=None, left=None, right=None,
dx=0, dy=0,
interval=1, is_collideable=True):
self._size = size
self._color = color
self._value = value
self._font = pygame.font.Font(None, self._size)
Sprite.__init__(self, self._create_surface(), angle,
x, y,
top, bottom, left, right,
dx, dy,
interval, is_collideable)

以下是我在自己的程序中尝试调用它的地方:

self.scorebox = games.Text (value = self.scorevar,
pygame.font.Font(ardarlingopentype, 50),
color = color.white,
x = 550,
y = 50)

如您所见,语法是错误的,但我该如何解决这个问题,以便我可以从我自己的程序中继承 Text 类,并使 FONT 成为我可以更改的可访问参数?

谢谢。

最佳答案

您的问题是,您对参数的排序不正确:有位置参数和关键字参数。所有关键字参数都必须位置参数之后。

这会起作用:

self.scorebox = games.Text (
pygame.font.Font(ardarlingopentype, 50),
value = self.scorevar,
color = color.white,
x = 550,
y = 50
)

关于python - 类继承,使用新参数重新定义 __init__ on,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652186/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com