用python在windows上安装TTF字体 [英] Installing TTF fonts on windows with python

查看:39
本文介绍了用python在windows上安装TTF字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Python 2.7 在 Windows 上安装新字体.首先,我将 myFont.ttf 复制到 windows Fonts 文件夹,然后将 My Font (True Type) 键添加到注册表 (HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts).现在我想声明系统已经安装了新字体.为此,我发现我应该使用 win32api.SendMessage,但我不知道如何为此方法提供所需的参数?

I want to install new fonts on windows with Python 2.7. First I copied myFont.ttf to windows Fonts folder then I Added My Font (True Type) key to registry (HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts). Now I want to declare system that a new font has been installed. For this I found that I should use win32api.SendMessage, But I don't know how to provide required arguments for this method?

有没有办法用python在windows上安装ttf字体?我用谷歌搜索,但找不到关于 Python 的有用数据.

Is there anyway to install ttf fonts on windows with python? I googled it but I couldn't find useful data on Python.

推荐答案

import win32api
import win32con
import ctypes

ctypes.windll.gdi32.AddFontResourceA("C:\\Users\\Username\\Desktop\\fontname.ttf")
win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_FONTCHANGE)

这篇关于用python在windows上安装TTF字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆