我正在python中构建一个hang子手游戏,并且由于某种原因,当试图通过函数def drawGameOver中的消息显示游戏时,出现以下错误:“'str'对象没有属性'render'”。我的代码有什么问题?我将如何去显示屏幕底部中间的“游戏结束”?我已经给出了我认为是唯一相关的代码。错误是针对直接在“#display游戏结束消息”评论之下的行。谢谢!Python - pygame错误'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
添加您遇到错误的行号。 – Stuart 2014-11-03 18:13:06
这个错误几乎意味着它说的是什么;某处你实际上并没有传递'Font.render()'返回的'pygame.Surface',你只是传递一个字符串。 – 2014-11-03 18:20:28