Well I put part of the traceback into google and apparently some other people have had the same problem: www.pyedpypers.org/forum/viewtopic.php?f=3&t=937....his solution was to use a different version of python. The thing is that I'm using Python 2.5 just like the book, and I'm using pygame 1.9.1release-py2.5 which is for python 2.5! On Thu, Sep 23, 2010 at 5:38 AM, LukePaireepinart <rabidpoob...@gmail.com>wrote:
> Looks to me like you either found a bug in the core pygame code for loading > the system font on Mac or you are calling that method wrong. I checked the > method and it seems like you should be able to do what you're doing; it > shouldn't find a sysfont called none so it should load the default. > If no one else gets around to it, I'll give it a test on my Mac after work > and let you know. > > ----------------------------- > Sent from a mobile device with a bad e-mail client. > ----------------------------- > > On Sep 23, 2010, at 6:41 AM, kevin hayes <kevino...@gmail.com> wrote: > > > Can someone tell me what to do (or what I need to get) to get this > program to work properly? > > When I run the code(straight out of the book), I get this: > > > > Traceback (most recent call last): > > File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 107, in > <module> > > main() > > File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 102, in main > > myLabel = showStats(drawColor, lineWidth) > > File "/Users/kevinhayes/Desktop/code/ch05/paint.py", line 67, in > showStats > > myFont = pygame.font.SysFont("None", 20) > > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py", > line 555, in SysFont > > initsysfonts() > > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py", > line 522, in initsysfonts > > fonts = initsysfonts_darwin() > > File > "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/pygame/sysfont.py", > line 422, in initsysfonts_darwin > > _search_osx_font_paths(fonts) > > UnboundLocalError: local variable 'fonts' referenced before assignment > > > > > > > > ******************************** > > > > here is the code: > > > > """ paint.py > > a simple paint program""" > > > > import pygame > > > > def checkKeys(myData): > > """test for various keyboard inputs""" > > > > #extract the data > > (event, background, drawColor, lineWidth, keepGoing) = myData > > #print myData > > > > if event.key == pygame.K_q: > > #quit > > keepGoing = False > > elif event.key == pygame.K_c: > > #clear screen > > background.fill((255, 255, 255)) > > elif event.key == pygame.K_s: > > #save picture > > pygame.image.save(background, "painting.bmp") > > elif event.key == pygame.K_l: > > #load picture > > background = pygame.image.load("painting.bmp") > > elif event.key == pygame.K_r: > > #red > > drawColor = (255, 0, 0) > > elif event.key == pygame.K_g: > > #green > > drawColor = (0, 255, 0) > > elif event.key == pygame.K_w: > > #white > > drawColor = (255, 255, 255) > > elif event.key == pygame.K_b: > > #blue > > drawColor = (0, 0, 255) > > elif event.key == pygame.K_k: > > #black > > drawColor = (0, 0, 0) > > > > #line widths > > elif event.key == pygame.K_1: > > lineWidth = 1 > > elif event.key == pygame.K_2: > > lineWidth = 2 > > elif event.key == pygame.K_3: > > lineWidth = 3 > > elif event.key == pygame.K_4: > > lineWidth = 4 > > elif event.key == pygame.K_5: > > lineWidth = 5 > > elif event.key == pygame.K_6: > > lineWidth = 6 > > elif event.key == pygame.K_7: > > lineWidth = 7 > > elif event.key == pygame.K_8: > > lineWidth = 8 > > elif event.key == pygame.K_9: > > lineWidth = 9 > > > > #return all values > > myData = (event, background, drawColor, lineWidth, keepGoing) > > return myData > > > > def showStats(drawColor, lineWidth): > > """ shows the current statistics """ > > myFont = pygame.font.SysFont("None", 20) > > stats = "color: %s, width: %d" % (drawColor, lineWidth) > > statSurf = myFont.render(stats, 1, (drawColor)) > > return statSurf > > > > def main(): > > pygame.init() > > screen = pygame.display.set_mode((640, 480)) > > pygame.display.set_caption("Paint: (r)ed, (g)reen, (b)lue, (w)hite, > blac(k), (1-9) width, (c)lear, (s)ave, (l)oad, (q)uit") > > > > background = pygame.Surface(screen.get_size()) > > background.fill((255, 255, 255)) > > > > clock = pygame.time.Clock() > > keepGoing = True > > lineStart = (0, 0) > > drawColor = (0, 0, 0) > > lineWidth = 3 > > > > while keepGoing: > > clock.tick(30) > > > > for event in pygame.event.get(): > > if event.type == pygame.QUIT: > > keepGoing = False > > elif event.type == pygame.MOUSEMOTION: > > lineEnd = pygame.mouse.get_pos() > > if pygame.mouse.get_pressed() == (1, 0, 0): > > pygame.draw.line(background, drawColor, lineStart, > lineEnd, lineWidth) > > lineStart = lineEnd > > elif event.type == pygame.KEYDOWN: > > myData = (event, background, drawColor, lineWidth, > keepGoing) > > myData = checkKeys(myData) > > (event, background, drawColor, lineWidth, keepGoing) = > myData > > screen.blit(background, (0, 0)) > > myLabel = showStats(drawColor, lineWidth) > > screen.blit(myLabel, (450, 450)) > > pygame.display.flip() > > > > if __name__ == "__main__": > > main() > > > > > *********************************************************************************** > > > > I'm using python 2.5 and pygame-1.9.1release-py2.5 on Mac osx > 10.4.11...any help would be appreciated. Thanks. Kevin >