0
我在查找錯誤時遇到了一些問題。當我嘗試運行代碼我得到以下輸出:TypeError:文本必須是unicode或字節
Traceback (most recent call last):
File "C:/Users/PC/Documents/Python_Projects/Segundo Teste/Game.py", line 133, in <module>
set_message(message)
File "C:/Users/PC/Documents/Python_Projects/Segundo Teste/Game.py", line 61, in set_message
message = font.render(text, True, black, white)
TypeError: text must be a unicode or bytes
這些代碼行:
if message != previous_message:
set_message(message) --> line 133
def set_message(text):
global message, previous_messsage
message = font.render(text, True, black, white) --> line 61
previous_messsage = message
你爲什麼從'font.render()'設置'previous_messsage'?它與** previous_message不一樣(注意'message'中's'字符的數目)。 – 2015-03-02 21:28:16
無論您傳遞給set_message(),都不能是字符串。嘗試在方法開頭打印:'print「消息:'{}'({})」。格式(消息,類型(消息))' – 2015-03-02 21:28:45
'font'是什麼?這是Pygame代碼嗎? – 2015-03-02 21:29:06