我的代码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',''.........]
1 回答
烙印99
TA贡献1829条经验 获得超13个赞
import os
list = []
for file in os.listdir(r'C:\Windows\Fonts'):
if file.endswith(".ttf"):
list.append(file)
print(list)
上面的代码会生成一个包含字体文件名的列表。
添加回答
举报
0/150
提交
取消