"""Sample code showing how the new tkFont code could be used. This is a simple and somewhat artificial example but shows a typical use of tkFont objects -- to control the appearance of a class of widgets. The issue is that setFontSize should work whether or not labelFont (a tkFont object created in setup) has been destroyed. So this example shows setFontSize being called twice: once before labelFont is destroyed and once after. So long as tkFont __del__ destroys the tk named font, the only way to use tk named fonts to control widget appearance is to keep track of the original tkFont object itself, and the headache I hoped to avoid by fixing the handling of the name argument to tkFont. """ import Tkinter import tkFont root = Tkinter.Tk() def setup(): """Set Tkinter so that the font for Labels is controlled by a tk named font. In other words, one can modify the tk named font to modify the appearance of all labels created after this routine has run. This is a separate subroutine so that the tkFont object used by this routine is deleted at the end, thus exposing a probem with tkFont as currently written. """ labelFont = tkFont.Font(family="helvetica") root.option_add("*Label.font", labelFont) setFontSize(12) def setFontSize(size): """Set a new font size for all labels. Warning: the default label font must be a tk named font. """ fontName = Tkinter.Label().cget("font") fontObj = tkFont.Font(name=fontName, exists=True) fontObj.configure(size=size) setup() l = Tkinter.Label(text="Sample Text") l.pack() root.after(1000, setFontSize, 24) root.after(2000, root.quit) root.mainloop()