如何获取 Tkinter 上可用字体的列表?

问题描述

如何获取 Tkinter 中可用字体的名称列表?

我尝试和使用的唯一字体是“Courier”和“Helvetica”,我尝试使用其他字体但它返回相同的认字体。

# this works
button = tk.Button(self.subframe,text="quit",command=master.destroy,highlightbackground='black',font='Helvectica 18')

# this does not work (the text remains the font)
button = tk.Button(self.subframe,font='Roboto 18')

(font used in the second example)

所以我不知道哪些字体可用,如果我能得到字体列表会很有帮助。

解决方法

你可以这样做

from tkinter import Tk,font
root = Tk()
print(font.families())