2017-08-01 45 views
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) 
+2

请添加完整的追溯,我们需要知道错误发生的位置以及确切的错误。另外''tkinter.font.Font'' *确实存在,是什么让你认为它不存在? –

+1

请将您的代码降低到[mcve]。 – ppperry

+0

错误和您的代码不匹配。该代码显示'tkinter.font.Font(...)',但错误消息显示'tkinter.font(...)' –

回答

0

直到创建根窗口后才能创建字体。

相关问题