簡體   English   中英

tkinter.font模塊對象不可調用

[英]tkinter.font module object not callable

我試圖制作一個簡單的平台游戲,但是,由於tkinder(更具體地說,tkfont或tkinder.font)是一個模塊,因此無法調用,因此無法顯示“ Game Over”消息。 在這里編碼。 完整的回溯是:

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)

您必須先創建根窗口,然后才能創建字體。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM