类型错误: 'pygame.表面"对象不可下标



我的Pygame项目有一个错误,这是代码

def text(window, text, loc, color, font_size):
font = pygame.font.Font('Fonts/Sticky_koala-Regular.ttf', font_size)

text = font.render(text, True, color)
window.blit(text, loc)
return (text)
text(window, "/" + numerictext(maxvariable), (variablebox[0][0] + variablebox[1], popuprect.top + 80), (255, 255, 255), 36)

如图所示,错误object is not subscriptable表示您正试图使用pygame曲面作为容器。从你向我们展示的情况来看,唯一存在这种情况的地方是你调用函数的那一刻:

text = drawText(
window,                                                    #surface where to blit the string
"/" + numerictext(maxvariable),                            #string to render
(variablebox[0][0] + variablebox[1], popuprect.top + 80),  #tuple of int of the location of the text on the window
(255, 255, 255),                                           #color of the rendered text
36)                                                        # dimension of the text 

因此,如果错误出现在您共享的代码片段中,则必须在loc中,调用variablebox[0][0]variablebox[1]之一

最新更新