pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## pygame.font

The font module allows for rendering TrueType fonts into a new Surface object. This module is optional and requires SDL_ttf as a dependency. You may want to check for pygame.font to import and initialize before attempting to use the module.
Most of the work done with fonts are done by using the actual Font objects. The module by itself only has routines to initialize the module and create Font objects with pygame.font.Font().
You can load fonts from the standard system fonts by using the pygame.font.SysFont() method. There are also other functions to help you work with system fonts.

Font | - create a new font object
SysFont | - create a pygame Font from system font resources
get_default_font | - get the name of the default font
get_fonts | - get a list of system font names
get_init | - get status of font module initialization
init | - initialize the display module
match_font | - find the filename for the named system font
quit | - uninitialize the font module

Font
`pygame.font.Font(file, size) -> Font`

This will create a new font object. The given file can be a filename or any python file-like object. The size represents the height of the font in pixels. The file argument can be 'None', which will use a plain default font.
You must have at least SDL_ttf-2.0.6 for file object support. You can load TTF and FON fonts.

SysFont
`pygame.font.SysFont(name, size, bold=0, italic=0) -> Font`

This will search the system fonts for the given font name. You can also enable bold or italic styles, and the appropriate system font will be selected if available.
This will always return a valid Font object, and will fallback on the builtin pygame font if the given font is not found.
Name can also be a comma separated list of names, in which case set of names will be searched in order. Pygame uses a small set of common font aliases, if the specific font you ask for is not available, a reasonable alternative may be used.

get_default_font
`pygame.font.get_default_font() -> string`

returns the filename for the default truetype font.

get_fonts
`pygame.font.get_fonts() -> list`

Returns the list of all found system fonts. Note that the names of the fonts will be all lowercase with spaces removed. This is how pygame internally stores the font names for matching.

get_init
`pygame.font.get_init() -> bool`

Returns true if the font module is currently intialized.

init
`pygame.font.init() -> None`

Manually initialize the font module. Will raise an exception if it cannot be initialized. It is safe to call this function if font is currently initialized.

match_font
`pygame.font.match_font(name, bold=0, italic=0) -> name`

This performs the same font search as the SysFont() function, only it returns the path to the TTF file that would be loaded. The font name can be a comma separated list of font names to try.
If no match is found, None is returned.

quit
`pygame.font.quit() -> none`

Manually uninitialize SDL_ttf's font system. It is safe to call this if font is currently not initialized.