You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ImageFont.truetype加载字体疑问:是否需指定扩展名及Tkinter字体名与TTF文件匹配问题

ImageFont.truetype加载字体疑问:是否需指定扩展名及Tkinter字体名与TTF文件匹配问题

我从tkinter的font模块里获取了可用字体的列表:

from tkinter import font
# ... 获取字体列表的相关代码
font.families()

不过在尝试通过ImageFont类选择字体时,我实在搞不懂怎么把上面拿到的字体名和对应的.ttf文件匹配起来。我现在是这么写的:

my_font = ImageFont.truetype(f"{some_font_from_above}.ttf")

请问这是大小写的问题吗?还是说字体名本身就和.ttf文件名不一样?

我现在一直遇到同一个错误:

self.font = core.getfont(
                ^^^^^^^^^^^^^
OSError: cannot open resource

谢谢!

备注:内容来源于stack exchange,提问作者qandira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 16:38:09