Im trying to use a different font in pygame but every time I run it I get this syntax error message
[Traceback (most recent call last):
File "C:\Python31\", line 22, in <module>
font1 = pygame.font.Font('C:\ActionIsShaded.ttf', 12)
IOError: unable to read font filename]

I tried getting rid of the qoutes around the file name but syntax just gave me an error and didn't even run the program

Please help and thanks in advance to anyone that gives me any suggestions.

Recommended Answers

All 7 Replies

Try this.

font1 = pygame.font.SysFont('ActionIsShaded', 12)

Try this.

font1 = pygame.font.SysFont('ActionIsShaded', 12)

IT works but it uses the default font and im trying to use a different font

Perhaps try lower case? I don't have Python on this computer so I can't test it right now

maybe I have to load it first but I dont know how to do that at all

Here is document in internet:

SysFont looks like for system fonts, not for file:

Also SysFont returns font, does not set it, if I understand correctly.
In this game it is used with render method of the font returned:

def __init__(self):
        self.font = pygame.font.SysFont("None", 30)
        self.text = "" = (320, 240)
   def update(self):
        self.image = self.font.render(self.text, 1, (0, 0, 0))
        self.rect = self.image.get_rect() =

what does it mean if I get this back
[Traceback (most recent call last):
File "C:\Python31\", line 26, in <module>
text2 = font1.render ('Work',False,WHITE,BLUE)
AttributeError: 'NoneType' object has no attribute 'render']

Here is a good PyGame font example ...

use of a customized font with PyGame:
download custom font from:

import pygame

def main():
    screen = pygame.display.set_mode((640, 480))
    pygame.display.set_caption("display some text")
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    # rgb tuple (0, 0, 0) is black
    background.fill((0, 0, 0))
    # makes sure the font file is in the working directory
    # or give the full path name
    myFont = pygame.font.Font("GringoNights.ttf", 40)
    # rgb tuple (255, 0, 0) is red
    # rgb tuple (255, 255, 0) is yellow
    label = myFont.render("Python in the Wild West", 1, (255, 0, 0))
    # use clock if you want to animate something
    #clock = pygame.time.Clock()
    keepGoing = True
    while keepGoing:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                keepGoing = False
        screen.blit(background, (0, 0))
        screen.blit(label, (100, 100))

if __name__ == "__main__":
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.