'How to get a list of installed windows fonts using python?

Stupid question, but how do I get a list of all the font names that are on my computer's system?



Solution 1:[1]

You could also use tkinter which would be better than list the font in C:\Windows\fonts, because windows can also store fonts in %userprofile%\AppData\Local\Microsoft\Windows\Fonts

List available font families in `tkinter`

Solution 2:[2]

The above answer is going to list all the fonts path from the /Windows/fonts dir. However, some people might also want to get the font title, its variations i.e., thin, bold, and font file name etc? Here's the code for that.

import sys, subprocess

_proc = subprocess.Popen(['powershell.exe', 'Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"'], stdout=sys.stdout)
_proc.communicate()

Now, for the people who want font paths. Here's the way using pathlib.

import pathlib

fonts_path = pathlib.PurePath(pathlib.Path.home().drive, os.sep, 'Windows', 'Fonts')
total_fonts = list(pathlib.Path(fonts_path).glob('*.fon'))
if not total_fonts:
    print("Fonts not available. Check path?")
    sys.exit()
return total_fonts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jeremie bergeron
Solution 2 Mujeeb Ishaque