Pygame字体模块,UnboundLocalError

时间:2016-02-15 21:23:57

标签: python macos python-2.7 pygame

我在我的mac上使用pygame-1.9.1运行python 2.7.11,32位版本。 使用python 3对Mac OS X的Pygame支持似乎有点混乱,所以我选择了这个。

这是我的代码:

import pygame
from pygame import *
pygame.init()
pygame.font.init()
DISPLAY = pygame.display.set_mode((400,400),pygame.RESIZABLE)
font = pygame.font.SysFont('freesansbold.ttf',25,True,False)
text = font.render("HELLO WORLD",True,BLACK)
screen.blit(text,[250,250])

它打破了:

 font = pygame.font.SysFont('freesansbold.ttf',25,True,False)

显示长错误消息:

Traceback (most recent call last):
  File "/Users/jcraster/Documents/Stuff", line 6, in <module>
    font = pygame.font.SysFont('freesansbold.ttf',25,True,False)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/sysfont.py", line 556, in SysFont
    initsysfonts()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/sysfont.py", line 523, in initsysfonts
    fonts = initsysfonts_darwin()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/sysfont.py", line 423, in initsysfonts_darwin
    _search_osx_font_paths(fonts)
UnboundLocalError: local variable 'fonts' referenced before assignment

我前往/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/sysfont.py并查看了sysfont.py的第423行:

def initsysfonts_darwin():
""" read the fonts on OSX.
"""

# if the X11 binary exists... try and use that.
#  Not likely to be there on pre 10.4.x ...
#    so still need to do other OSX specific method below.
if os.path.exists("/usr/X11/bin/fc-list"):
    fonts = initsysfonts_unix()

# we look for the default paths.
_search_osx_font_paths(fonts)

return fonts

作为一个新手,在我看来问题是/usr/X11/bin/fc-list不存在 - 但我该如何解决? 编辑:或fonts = initsysfonts_unix()是个问题。无论哪种方式,都没有任务:(

很抱歉这篇长篇文章,我非常感谢你的帮助!

修复! 问题在于/ usr / X11 / bin / fc-list - 这已经过时了。字体现在存储在/ System / Library。

0 个答案:

没有答案
相关问题