Python:TypeError:文本必须是unicode或字节

2024-10-05 14:29:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在pygame中将一个列表放到一个表面上,但是prompts = contactFont.render(fields, True, (171,0,0))行导致了上述错误,我不知道为什么。

class AddPage(Page):

    ...

    def textInputs(self):
        fields = ["First Name:", "Last Name:", "Address:", "Mobile:", "Telephone:", "Email:"]
        contactFont = pygame.font.SysFont("trebuchet ms", 18)
        y = 20

        for i in fields:
            #Error here
            prompts = contactFont.render(fields, True, (171,0,0))
            self.intermediate2.blit(prompts, (5,y))
            pygame.draw.line(self.intermediate2, (0,0,0), (5, (y+20)), (320, (y+20)), 1)
            y += 30

我试着用[x.encode('utf-8') for x in fields]fields列表编码成unicode,但是什么也没发生,怎么了?


Tags: nameinselftruefields列表for错误