Next / Previous / Contents / TCC Help System / NM Tech homepage

4.4. Type fonts

Depending on your platform, there may be up to three ways to specify type style.

To get a list of all the families of fonts available on your platform, call this function:

    tkFont.families()

The return value is a list of strings. Note: You must create your root window before calling this function.

These methods are defined on all Font objects:

.actual ( option=None )

If you pass no arguments, you get back a dictionary of the font's actual attributes, which may differ from the ones you requested. To get back the value of an attribute, pass its name as an argument.

.cget ( option )

Returns the value of the given option.

.configure ( option, ... )

Use this method to change one or more options on a font. For example, if you have a Font object called titleFont, if you call titleFont.configure ( family="times", size=18 ), that font will change to 18pt Times and any widgets that use that font will change too.

.copy()

Returns a copy of a Font object.

.measure ( text )

Pass this method a string, and it will return the number of pixels of width that string will take in the font. Warning: some slanted characters may extend outside this area.

.metrics ( option )

If you call this method with no arguments, it returns a dictionary of all the font metrics. You can retrieve the value of just one metric by passing its name as an argument. Metrics include:

ascentNumber of pixels of height between the baseline and the top of the highest ascender.
descentNumber of pixels of height between the baseline and the bottom of the lowest ascender.
fixedThis value is 0 for a variable-width font and 1 for a monospaced font.
linespaceNumber of pixels of height total. This is the leading of type set solid in the given font.