[Tutor] Trouble creating a pygame.font.SysFont, was Re: (no subject)

William Becerra it.iswill at yahoo.com
Mon Dec 1 10:07:08 CET 2014


It seems I forgot to write pygame.init() Thank you guys for your time it is much appreciated. 
 

     On Saturday, 29 November 2014, 15:31, Peter Otten <__peter__ at web.de> wrote:
   

 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.

_______________________________________________
Tutor maillist  -  Tutor at 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/20141201/89c53e21/attachment.html>


More information about the Tutor mailing list