我想使用与我的python程序位于同一个目录中的字体,但实际上python会搜索windows字体文件夹,我应该如何修复它呢?
(我想给我的程序字体路径,或者导入字体以便在我的标签中使用)
例如:在这里,如果位于字体文件夹中的字体myfont
,我的程序将工作,但如果没有,它将显示为默认字体。
from tkinter import * root = Tk() my_lab = Label(root,font=("myfont" ,10 )).place(x=1,y=1)
我用过font=(f"path/to/font",10)
,但它不起作用
发布于 2020-02-18 03:58:42
问题:如何在tkinter中使用自定义字体路径? ONLY
参考
def loadfont(fontpath, private=True, enumerable=False)
将函数更改为Python 3
def loadfont(fontpath, private=True, enumerable=False):
...
# For 3.x, you have to convert the isinstance checks to bytes and str
if isinstance(fontpath, bytes):
pathbuf = create_string_buffer(fontpath)
AddFontResourceEx = windll.gdi32.AddFontResourceExA
elif isinstance(fontpath, str):
pathbuf = create_unicode_buffer(fontpath)
AddFontResourceEx = windll.gdi32.AddFontResourceExW
...
尝试参数的变体private=False
**,** enumerable=True
,并确保您输入了正确的字体名。
运行函数loadfont(...)
,如:
loadfont("path//to//font.ttf", private=False, enumerable=True)
https://stackoverflow.com/questions/60248724
复制