tkinter.font 模块对象不可调用



我正在尝试制作一个简单的平台游戏,但是,我无法显示"Game Over"消息,因为tkinder,更具体地说,tkfont或tkinder.font是一个模块,不能调用。 在这里编码。完整的回溯是:

Traceback (most recent call last):
File "C:UsersiD StudentDesktopConnor MEndless 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:UsersiD StudentDesktopConnor MEndless platformer.py", line 
31, in <module>
helv36 = tkinter.font.Font(family="Helvetica",size=36,weight="bold")
File "C:Python35libtkinterfont.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)

在创建根窗口之前,无法创建字体。

最新更新