Python——pygame错误';str对象没有属性';渲染';

Python——pygame错误';str对象没有属性';渲染';,python,pygame,Python,Pygame,我正在用python构建一个hangman游戏,由于某种原因,当尝试在函数def drawGameOver中显示游戏结束消息时,我得到以下错误:“'str'对象没有属性'render'”。我的代码有什么问题?我将如何在屏幕的中间底部显示“游戏结束”?我已经给出了我认为唯一相关的代码。错误出现在“#显示游戏结束消息”注释正下方的行中。谢谢 # this function draws the game over screen def drawGameOver(screen, fontObj,

我正在用python构建一个hangman游戏,由于某种原因,当尝试在函数def drawGameOver中显示游戏结束消息时,我得到以下错误:“'str'对象没有属性'render'”。我的代码有什么问题?我将如何在屏幕的中间底部显示“游戏结束”?我已经给出了我认为唯一相关的代码。错误出现在“#显示游戏结束消息”注释正下方的行中。谢谢

# this function draws the game over screen    
def drawGameOver(screen, fontObj, gameOverMsg, secretWord):
# draw a filled rectangle
pygame.draw.rect(screen,(0,0,255),(0,375,640,100))
# draw a border rectangle
# display the game over message
overMsg = fontObj.render(gameOverMsg, True, (255,255,255),(0,0,0))
overRect = overMsg.get_rect()
screen.blit(overMsg,overRect)
# display the secret word
print("")

def main():
# initialize pygame
pygame.init()
# create the screen
screen = pygame.display.set_mode((640,440))
# fill the screen w/ white
screen.fill((255,255,255))

fontObj = pygame.font.SysFont('bookantiqua', 28, True, False)
# here is the magic: making the text input
# create an input with a max length of 45,
# and a red color and a prompt saying 'type here: '
txtbx = eztext.Input(x=0, y=350, color=(0,0,0), prompt='You entered: ')

# get the secret word
secretWord = getRandomWord(words)
#variables to hold the incorrect and correct letters
missedLetters = ""
correctLetters = ""
#gameoverMsg is initialized to be empty
gameOverMsg = "Game Over"
#game is not over yet
gameIsDone = False

看起来您传递的
fontObj
是一个字符串,而不是字体对象。这是您试图渲染的唯一内容。

问题是我需要在这个特定函数中重新定义fontObj。

添加获取错误的行号。错误几乎就是它所说的;在某个地方,您实际上并没有传递
pygame.Surface
Font.render()返回的
Font.render()
值,您只是传递了一个字符串。您能更具体一点吗?fontObj被定义为字体,render()的第一个参数是一个字符串,它应该是字符串。您在这里正确地定义了fontObj fontObj=pygame.font.SysFont('BookAngia',28,True,False)。我只能假设在此之后的某个地方,或者在调用drawGameOver时,fontObj被重新定义为字符串。