If you still don't have a solution I suggest using the default font for pygame freesansbold.tiff it is located in the python library files just search for it in the python-pygame directory. I think your code fails because it does not pick the font you wanted hence not initialised.
Below is a sample code of a font been used from a file you can equally download fonts from google fonts fontObj = pygame.font.Font("freesansbold.ttf", 40) fontObj is our object been initialised. Hope it helps On Sun, Nov 30, 2014 at 12:00 PM, <tutor-requ...@python.org> wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. (no subject) (William) > 2. Trouble creating a pygame.font.SysFont, was Re: (no subject) > (Peter Otten) > 3. Re: (no subject) (Danny Yoo) > 4. Re: (no subject) (Japhy Bartlett) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 29 Nov 2014 11:31:57 +0200 > From: William <it.isw...@yahoo.com> > To: tutor@python.org > Subject: [Tutor] (no subject) > Message-ID: <5479928d.9000...@yahoo.com> > Content-Type: text/plain; charset=utf-8; format=flowed > > Hello there I'm using Python 3.4 running on Ubuntu 14.04LTS > I'm new to programming and also new to linux > I'm trying to learn the pygame library > I was reading : > > > http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5 > > On the section on how to draw text the writer has the following code > | > font ||=||pygame.font.SysFont(||'Calibri'||, ||25||, ||True||, ||False||)| > |text ||=||font.render(||"My text"||,||True||,BLACK) > ||screen.blit(text, [||250||, ||250||]) > > When I run the code using the IDLE the Python shell gives me the > following error > > Traceback (most recent call last): > File "/home/william/Desktop/Pygame/Python 3X/Drawing_Shapes.py", line > 48, in <module> > font = pygame.font.SysFont('Calibri', 25, True, False) > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > 614, in SysFont > return constructor(fontname, size, set_bold, set_italic) > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > 537, in font_constructor > font = pygame.font.Font(fontpath, size) > pygame.error: font not initialized > > > I think the problem is that the fonts in Ubuntu are probably stored in a > different > location than in Windows OS.And therefore python can not find it using > the SysFont > method > Can anyone give me any suggestion on how to edit the code so that I can > write text > on my graphics? > Thank you. > | > > > ------------------------------ > > Message: 2 > Date: Sat, 29 Nov 2014 14:31:04 +0100 > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Subject: [Tutor] Trouble creating a pygame.font.SysFont, was Re: (no > subject) > Message-ID: <m5chqo$e54$1...@ger.gmane.org> > Content-Type: text/plain; charset="ISO-8859-1" > > William wrote: > > Hello William; please provide a meaningful subject line so that your > readers > get a hint whether your question is in their area of expertise. > > > > Hello there I'm using Python 3.4 running on Ubuntu 14.04LTS > > I'm new to programming and also new to linux > > I'm trying to learn the pygame library > > I was reading : > > > > > > http://programarcadegames.com/index.php?chapter=introduction_to_graphics&lang=en#section_5 > > > > On the section on how to draw text the writer has the following code > > | > > font ||=||pygame.font.SysFont(||'Calibri'||, ||25||, ||True||, > ||False||)| > > |text ||=||font.render(||"My text"||,||True||,BLACK) > > ||screen.blit(text, [||250||, ||250||]) > > That is very hard to read. If you have to post Python code please do it in > plain text without those funny "|". Thank you. > > > When I run the code using the IDLE the Python shell gives me the > > following error > > > > Traceback (most recent call last): > > File "/home/william/Desktop/Pygame/Python 3X/Drawing_Shapes.py", line > > 48, in <module> > > font = pygame.font.SysFont('Calibri', 25, True, False) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > > 614, in SysFont > > return constructor(fontname, size, set_bold, set_italic) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > > 537, in font_constructor > > font = pygame.font.Font(fontpath, size) > > pygame.error: font not initialized > > > > > > I think the problem is that the fonts in Ubuntu are probably stored in a > > different > > location than in Windows OS.And therefore python can not find it using > > the SysFont > > method > > Can anyone give me any suggestion on how to edit the code so that I can > > write text > > on my graphics? > > Quoting the page you link to: > > """ > The first code a Pygame program needs to do is load and initialize the > Pygame library. Every program that uses Pygame should start with these > lines: > > Importing and initializing Pygame > # Import a library of functions called 'pygame' > import pygame > # Initialize the game engine > pygame.init() > """ > > Did you follow that advice? If you did and your script is reasonably short > please post it here so that we can have a look or try to run it ourselves. > > > > ------------------------------ > > Message: 3 > Date: Sat, 29 Nov 2014 12:26:16 -0800 > From: Danny Yoo <d...@hashcollision.org> > To: William <it.isw...@yahoo.com.dmarc.invalid> > Cc: Python Tutor Mailing List <tutor@python.org> > Subject: Re: [Tutor] (no subject) > Message-ID: > < > cagzapf6isqciv+nsqr5wjk0ta8mtqwcvshonqtz_emcebr1...@mail.gmail.com> > Content-Type: text/plain; charset=UTF-8 > > > When I run the code using the IDLE the Python shell gives me the > following > > error > > > > Traceback (most recent call last): > > File "/home/william/Desktop/Pygame/Python 3X/Drawing_Shapes.py", line > 48, in > > <module> > > font = pygame.font.SysFont('Calibri', 25, True, False) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > 614, > > in SysFont > > return constructor(fontname, size, set_bold, set_italic) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > 537, > > in font_constructor > > font = pygame.font.Font(fontpath, size) > > pygame.error: font not initialized > > > Hi William, > > Please check with the pygame folks on this one; pygame is a > third-party library, and we at Tutor might not be too familiar with > the library. There should be an active pygame-users mailing list at > the following URL: > > http://www.pygame.org/wiki/info > > According to web searches, the term "pygame.error: font not > initialized" means that you may have forgotten to initialize PyGame > first. > > Reference: http://inventwithpython.com/pygame/chapter2.html, where > they say: "If you ever see an error message like pygame.error: font > not initialized, check to see if you forgot to call pygame.init() at > the start of your program." > > > Again, I have no direct experience with PyGame, so I can not confirm > that this will fix the issue for your own program. This is why you'll > probably want to ask on pygame-users. > > > Good luck to you! > > > ------------------------------ > > Message: 4 > Date: Sat, 29 Nov 2014 13:06:05 -0600 > From: Japhy Bartlett <ja...@pearachute.com> > To: William <it.isw...@yahoo.com.dmarc.invalid> > Cc: Python Tutor <tutor@python.org> > Subject: Re: [Tutor] (no subject) > Message-ID: > <CANTsVHJnKkrzj=WR2gbSpCCDOVw5LGpVJpE= > h5zjyzutnoa...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > It looks like this is a pretty common stumbling block, and you need to call > `pygame.font.init()` before the code you pasted. > > Also.. the way you've pasted that code has added '||' all over the place. > Not sure what's going on there (some sort of tabs/spaces thing?), but it > makes it extremely hard to read! > > On Sat, Nov 29, 2014 at 3:31 AM, William <it.isw...@yahoo.com.dmarc.invalid > > > wrote: > > > Hello there I'm using Python 3.4 running on Ubuntu 14.04LTS > > I'm new to programming and also new to linux > > I'm trying to learn the pygame library > > I was reading : > > > > http://programarcadegames.com/index.php?chapter= > > introduction_to_graphics&lang=en#section_5 > > > > On the section on how to draw text the writer has the following code > > | > > font ||=||pygame.font.SysFont(||'Calibri'||, ||25||, ||True||, > ||False||)| > > |text ||=||font.render(||"My text"||,||True||,BLACK) > > ||screen.blit(text, [||250||, ||250||]) > > > > When I run the code using the IDLE the Python shell gives me the > following > > error > > > > Traceback (most recent call last): > > File "/home/william/Desktop/Pygame/Python 3X/Drawing_Shapes.py", line 48, > > in <module> > > font = pygame.font.SysFont('Calibri', 25, True, False) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > > 614, in SysFont > > return constructor(fontname, size, set_bold, set_italic) > > File "/usr/local/lib/python3.4/dist-packages/pygame/sysfont.py", line > > 537, in font_constructor > > font = pygame.font.Font(fontpath, size) > > pygame.error: font not initialized > > > > > > I think the problem is that the fonts in Ubuntu are probably stored in a > > different > > location than in Windows OS.And therefore python can not find it using > the > > SysFont > > method > > Can anyone give me any suggestion on how to edit the code so that I can > > write text > > on my graphics? > > Thank you. > > | > > _______________________________________________ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://mail.python.org/pipermail/tutor/attachments/20141129/fc69c773/attachment-0001.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > > ------------------------------ > > End of Tutor Digest, Vol 129, Issue 73 > ************************************** >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor