一个愚蠢的问题,但是我怎样才能得到我计算机系统中所有字体名称的列表呢?
发布于 2020-09-26 03:08:52
这只是一个在Windows\fonts中列出文件的问题
import os
print(os.listdir(r'C:\Windows\fonts'))发布于 2021-08-15 23:31:56
上面的答案将列出/Windows/fonts dir中的所有字体路径。但是,有些人可能还想获得the font title, its variations i.e., thin, bold, and font file name etc?,下面是实现该目的的代码。
import sys, subprocess
_proc = subprocess.Popen(['powershell.exe', 'Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"'], stdout=sys.stdout)
_proc.communicate()现在,对于那些想要字体路径的人。下面是使用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_fontshttps://stackoverflow.com/questions/64070050
复制相似问题