Stupid question, but how do I get a list of all the font names that are on my computer's system?
Stupid question, but how do I get a list of all the font names that are on my computer's system?
This is just a matter of listing the files in Windows\fonts:
import os
print(os.listdir(r'C:\Windows\fonts'))
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
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