Skip to main content
 首页 » 编程设计

Python3如何安装.ttf字体文件

2024年12月31日10xing901022

我想用 python3(更精确的 Python 3.6)代码在 Windows 10 上安装 .ttf 字体文件,我用谷歌搜索,但我唯一找到的是这个 Install TTF fonts on windows with python ,我测试了它,但它没有做任何事情。有没有办法用 python3 代码安装 .ttf?

提前致谢。

请您参考如下方法:

This图书馆似乎很有前途(我自己还没有尝试过)。

正在安装

pip install --user fonttools 

或

pip3 install --user fonttools 

代码

from fontTools.ttLib import TTFont 
font = TTFont('/path/to/font.ttf') 

然后使用font.save方法:

Definition: font.save(self, file, reorderTables=True)

Docstring: Save the font to disk. Similarly to the constructor, the 'file' argument can be either a pathname or a writable file object.