我的代码
import tkinter as tk
from tkinter import font
root = tk.Tk()
fonts = list(font.families())
fonts.sort()
print(fonts)
root.mainloop()
输出
['Arial', 'Arial Baltic', 'Arial Black', 'Arial CE', 'Arial CYR', 'Arial Greek', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial TUR', 'Arial Unicode MS', 'Baskerville Old Face', 'Batang', 'BatangChe', 'Bauhaus 93', 'Bell MT', 'Berlin Sans FB', 'Berlin Sans FB Demi', 'Bernard MT Condensed', 'Blackadder ITC', 'Bodoni MT', 'Bodoni MT Black', 'Bodoni MT Condensed', 'Bodoni MT Poster Compressed', 'Book Antiqua', 'Bookman Old Style', 'Bookshelf Symbol 7', 'Bradley Hand ITC', 'Britannic Bold', 'Broadway', 'Browallia New', 'BrowalliaUPC', 'Brush Script MT', 'Calibri', 'Calibri Light', 'Californian FB', 'Calisto MT', 'Cambria', 'Cambria Math', 'Candara', 'Castellar', 'Centaur', 'Century', 'Century Gothic', 'Century']
但是,我希望列表包含字体文件的实际名称,该名称显示在字体属性中。
['arial','arialbi','ariblk',''.........]
答案 0 :(得分:0)
import os
list = []
for file in os.listdir(r'C:\Windows\Fonts'):
if file.endswith(".ttf"):
list.append(file)
print(list)
以上代码将生成一个包含字体文件名的列表。