如何获取 openpyxl 或 python-pptx 中所有可用字体的列表?

How to get list of all available fonts in openpyxl or python-pptx?

我正在尝试在 Tkinter 中创建一个组合框,其中包含 Microsoft Office 中所有可用字体的列表。我希望 python-pptx 或 openpyxl 库有一个列表,但在阅读文档后,我找不到位置。 openpyxl 或 python-pptx 中存储的字体名称字符串列表在哪里?

这似乎可以使用 python-pptx:

>>> from pptx.text.fonts import FontFiles
>>> FontFiles._installed_fonts()
{('Agency FB', True, False): 'C:\Windows\Fonts\AGENCYB.TTF', ...

如您在 its source code 中所见,此方法 returns“将字体描述符映射到其字体文件路径的字典”。此外,您可以查看相同 class 的 _iter_font_files_in 方法以了解什么是“字体描述符”:

Each item is a key/value pair. The key is a (family_name, is_bold, is_italic) 3-tuple, like ('Arial', True, False), and the value is the absolute path to the font file.

因此,('Agency FB', True, False) 表示:“此路径中的字体名为 'Agency FB',是粗体而不是斜体”。