Connor
Connor

Reputation: 143

tkinter.font module object not callable

I'm attempting to make a simple platformer game, however, I can't show the "Game Over" message because tkinder, and more specifically, tkfont, or tkinder.font, is a module, and cannot be called. Code here. The full traceback is:

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 throws this traceback:

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'

which I assume to be an error in tkinter itself. Relevant code:

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)

Upvotes: 0

Views: 708

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385800

You can't create a font until after you've created a root window.

Upvotes: 1

Related Questions