tkinter.font模块对象不可调用

时间:2017-08-01 20:02:17

标签: python fonts

我正在尝试制作一个简单的平台游戏,但是,我无法显示“Game Over”消息,因为tkinder,更具体地说,tkfont或tkinder.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)

1 个答案:

答案 0 :(得分:1)

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