Probably over my head... Trying to get Font Names

Fredrik Lundh fredrik at pythonware.com
Fri Feb 18 14:03:49 EST 2005


"Samantha" <samantha7395 at hotmail.com> wrote:

>I am attempting to extract the Font Names from the installed windows fonts. I am having a heck of a 
>time getting these rather than the file names. Examples can be seen by going to Control Panel > 
>Fonts

here's one way to do it (using Tkinter):

>>> import Tkinter, tkFont
>>> tk = Tkinter.Tk()
>>> tkFont.families()
('System', 'Terminal', 'Fixedsys', 'Roman', 'Script', 'Modern', 'Small Fonts', 'MS Serif', ...)

here's another way (using PIL):

import os
from PIL import ImageFont

fontdir = os.path.join(os.environ["windir"], "fonts")

for fontfile in os.listdir(fontdir):
  try:
    font = ImageFont.truetype(os.path.join(fontdir, fontfile), 1)
  except IOError:
    pass
  else:
    print font.font.family, font.font.style

(this prints a list of family/style combinations).  You can get PIL from

    http://www.pythonware.com/products/pil/ (1.1.4)
    http://effbot.org/downloads/#pil (1.1.5 betas)

</F> 






More information about the Python-list mailing list