【发布时间】:2021-06-11 19:46:27
【问题描述】:
我正在尝试制作 5 个屏幕来显示有关团队的信息,并且需要在每个屏幕中打印一些文本。我怎样才能避免所有这些行?
fonte = pygame.font.SysFont('Times New Roman', 20)
nomeEquipe = fonte.render("Nome da Equipe", True, preto)
nomeDavid = fonte.render("David Waters Teixeira Rodrigues", True, preto)
nomeRafael = fonte.render("Rafael Pereira de Souza", True, preto)
nomeVicente = fonte.render("Vicente de Paulo Vidal Alencar", True, preto)
nomeVictor = fonte.render("Victor Jerrysson Gama Bastos", True, preto)
nomeWillian = fonte.render("Willian Alves Batista", True, preto)
funcaoDavid = fonte.render("Função: menu inicial", True, preto)
funcaoRafael = fonte.render("Função: tela da equipe", True, preto)
funcaoVicente = fonte.render("Função: tela sobre", True, preto)
funcaoVictor = fonte.render("Função: jogo", True, preto)
funcaoWillian = fonte.render("Função: jogo", True, preto)
我试图实现这个:
class Fonte:
def __init__(self, fonte, tamanho):
pygame.font.SysFont.__init__(self)
self.fonte = fonte
self.tamanho = tamanho
class Tela:
def __init__(self, texto, antialias, cor):
Fonte.render.__init__(self)
self.texto = texto
self.antialias = antialias
self.cor = cor
fonte = Fonte('Times New Roman', 20)
nomeEquipe = Tela("Nome da Equipe", True, preto)
但我收到此错误:
Traceback (most recent call last):
File "/home/rafael/teste.py", line 55, in <module>
nomeEquipe = Tela("Nome da Equipe", True, preto)
File "/home/rafael/teste.py", line 45, in __init__
Fonte.render.__init__(self)
AttributeError: type object 'Fonte' has no attribute 'render'
【问题讨论】:
-
我很抱歉,但是:
but isn't working不是问题。似乎是什么问题? -
请使用完整的错误回溯更新您的question。
-
我做到了,谢谢你的信息。
-
我不确定你的意思。你想减少什么?
-
@Rabbid76 我的意思是,行中有很多重复,我不能做点什么来避免这种情况吗?