Listing Available Fonts For Pyprocessing
Today’s post is a short note-to-self.
This script lists available fonts and renders a small preview using Tkinter and pyprocessing.
from pyprocessing import * import Tkinter import tkFont t = Tkinter.Toplevel() # without root window the following line fails fonts = tkFont.families() t.destroy() size(1500,900) fill(0) rect(0,0,1500,900) fill(255) fontsize=14 lineheight=fontsize*1.2 y=lineheight x=0 for font_name in fonts: print font_name font = createFont(font_name, fontsize) textFont(font) text("Hello world! ("+font_name+")", x,y,1000,66) y+=lineheight if y >= 900: x+=500 y=lineheight run()
On the TODO list:
- Find out how to turn these fonts bold or italics.
Hi, in the pyprocessing source, createFont is defined as:
def createFont(family = None, size = 16, bold=False, italic=False):
Thus, you can see that if True is supplied for the bold or italic optional arguments, one can make the fonts bold, or italicized. Hope this helps with your todo!
Thanks! I’ll give it a try.