How to Create a List of Fonts in Python?

Estimated read time 1 min read

To create a list of fonts in Python, you can use the pygame library. Here’s an example code that creates a list of fonts installed on your system using the pygame.font.get_fonts() function:

import pygame

# initialize pygame library
pygame.init()

# get a list of fonts installed on the system
fonts_list = pygame.font.get_fonts()

# print the list of fonts
print(fonts_list)

In this example, we first import the pygame library and initialize it using the pygame.init() function. Then we use the pygame.font.get_fonts() function to get a list of fonts installed on the system. Finally, we print the list of fonts using the print() function.

Note that the pygame library needs to be installed before you can use it. You can install it using pip by running the command pip install pygame in your command prompt or terminal.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply