【发布时间】:2019-09-19 22:49:42
【问题描述】:
我目前正在制作一个小游戏,但它显示了一个奇怪的错误消息。即:
'Pygame Error': Font Not Initialized
这是什么意思?
这是我的代码:
import pygame, random, sys, os, time
import sys
from pygame.locals import *
WINDOWWIDTH = 800
WINDOWHEIGHT = 600
levens = 3
dead = False
Mousevisible = False
def terminate():
pygame.quit()
sys.exit()
def waitForPlayerToPressKey():
while True:
for event in pygame.event.get():
if event.type == QUIT:
terminate()
if event.type == KEYDOWN:
if event.key == K_ESCAPE: #escape quits
terminate()
return
def drawText(text, font, surface, x, y):
textobj = font.render(text, 1, TEXTCOLOR)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)
#fonts
font = pygame.font.SysFont(None, 30)
#def gameover():
#if dead == True:
#pygame.quit
# set up pygame, the window, and the mouse cursor
pygame.init()
mainClock = pygame.time.Clock()
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('hit the blocks')
pygame.mouse.set_visible(Mousevisible)
# "Start" screen
drawText('Press any key to start the game.', font, windowSurface, (WINDOWWIDTH / 3) - 30, (WINDOWHEIGHT / 3))
drawText('And Enjoy', font, windowSurface, (WINDOWWIDTH / 3), (WINDOWHEIGHT / 3)+30)
pygame.display.update()
waitForPlayerToPressKey()
zero=0
这是错误:
Traceback (most recent call last):
File "C:\Users\flori\AppData\Local\Programs\Python\Python37-32\schietspel.py", line 30, in <module>
font = pygame.font.SysFont(None, 30)
File "C:\Users\flori\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\sysfont.py", line 320, in SysFont
return constructor(fontname, size, set_bold, set_italic)
File "C:\Users\flori\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\sysfont.py", line 243, in font_constructor
font = pygame.font.Font(fontpath, size)
pygame.error: font not initialized
【问题讨论】:
-
如果您不提供您的代码(或其相关部分),我们将无法为您提供帮助。
-
总是将完整的错误消息(完整的 Traceback)放在有问题的地方(作为文本,而不是屏幕截图)。还有其他有用的信息。它应该告诉你你在哪一行代码中遇到了问题。
-
显示您的代码 - 我们无法在您的脑海中阅读。
-
一开始您应该使用
Google来查找有关'Pygame Error': Font Not Initialized的更多信息。也许有人已经有这个问题,他解决了。这样你就可以在几个小时前得到答案。
标签: python python-3.x pygame