0
我試圖做一個簡單的一些遊戲,但是,我不能顯示「遊戲結束」消息,因爲tkinder,更具體地說,tkfont或tkinder.font,是一個模塊,並且不能被調用。 代碼在這裏。完整回溯是:tkinter.font模塊對象不可調用
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font(family="Helvetica",size=36,weight="bold")
TypeError: 'module' object is not callable
tkinter.font.Font拋出這個回溯:
Traceback (most recent call last):
File "C:\Users\iD Student\Desktop\Connor M\Endless platformer.py", line
31, in <module>
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
File "C:\Python35\lib\tkinter\font.py", line 93, in __init__
tk.call("font", "create", self.name, *font)
AttributeError: 'NoneType' object has no attribute 'call'
我以爲是在Tkinter的本身就是一個錯誤。相關代碼:
import tkinter
from tkinter.font import *
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
def draw_text(display_string, font, surface, x_pos, y_pos):
text_display = font.font(display_string, 1, (0, 0, 0))
surface.blit(text_display, (x_pos, y_pos))
#Ends the game if the player dies
if y >640:
endgame = True
if endgame:
draw_text("GAME OVER", helv36, screen, 50, 50)
請添加完整的追溯,我們需要知道錯誤發生的位置以及確切的錯誤。另外''tkinter.font.Font'' *確實存在,是什麼讓你認爲它不存在? –
請將您的代碼降低到[mcve]。 – ppperry
錯誤和您的代碼不匹配。該代碼顯示'tkinter.font.Font(...)',但錯誤消息顯示'tkinter.font(...)' –