Tk Built-In Commands
font - Create and inspect fonts.
font option ?arg arg ...?
The font command provides several facilities for dealing with
fonts, such as defining named fonts and inspecting the actual attributes of
a font. The command has several different forms, determined by the
first argument. The following forms are currently supported:
font actual font ?-displayof window? ?option?
Returns information about the the actual attributes that are obtained when
font is used on window's display; the actual attributes obtained
may differ from the attributes requested due to platform-dependant
limitations, such as the availability of font families and pointsizes.
font is a font description; see FONT DESCRIPTIONS below. If the
window argument is omitted, it defaults to the main window. If
option is specified, returns the value of that attribute; if it is
omitted, the return value is a list of all the attributes and their values.
See FONT OPTIONS below for a list of the possible attributes.
font configure fontname ?option? ?value option value ...?
Query or modify the desired attributes for the named font called
fontname. If no option is specified, returns a list describing
all the options and their values for fontname. If a single option
is specified with no value, then returns the current value of that
attribute. If one or more option-value pairs are specified,
then the command modifies the given named font to have the given values; in
this case, all widgets using that font will redisplay themselves using the
new attributes for the font. See FONT OPTIONS below for a list of the
font create ?fontname? ?option value ...?
Creates a new named font and returns its name. fontname specifies the
name for the font; if it is omitted, then Tk generates a new name of the
form fontx, where x is an integer. There may be any number
of option-value pairs, which provide the desired attributes for
the new named font. See FONT OPTIONS below for a list of the possible
font delete fontname ?fontname ...?
Delete the specified named fonts. If there are widgets using the named font,
the named font won't actually be deleted until all the instances are
released. Those widgets will continue to display using the last known values
for the named font. If a deleted named font is subsequently recreated with
another call to font create, the widgets will use the new named font
and redisplay themselves using the new attributes of that font.
font families ?-displayof window?
The return value is a list of the case-insensitive names of all font families
that exist on window's display. If the window argument is
omitted, it defaults to the main window.
font measure font ?-displayof window? text
Measures the amount of space the string text would use in the given
font when displayed in window. font is a font description;
see FONT DESCRIPTIONS below. If the window argument is omitted, it
defaults to the main window. The return value is the total width in pixels
of text, not including the extra pixels used by highly exagerrated
characters such as cursive ``f''. If the string contains newlines or tabs,
those characters are not expanded or treated specially when measuring the
font metrics font ?-displayof window? ?option?
Returns information about the metrics (the font-specific data), for
font when it is used on window's display. font is a font
description; see FONT DESCRIPTIONS below. If the window argument is
omitted, it defaults to the main window. If option is specified,
returns the value of that metric; if it is omitted, the return value is a
list of all the metrics and their values. See FONT METRICS below for a list
of the possible metrics.
The return value is a list of all the named fonts that are currently defined.
The following formats are accepted as a font description anywhere
font is specified as an argument above; these same forms are also
permitted when specifying the -font option for widgets.
The name of a named font, created using the font create command. When
a widget uses a named font, it is guaranteed that this will never cause an
error, as long as the named font exists, no matter what potentially invalid
or meaningless set of attributes the named font has. If the named font
cannot be displayed with exactly the specified attributes, some other close
font will be substituted automatically.
The platform-specific name of a font, interpreted by the graphics server.
This also includes, under X, an XLFD (see ) for which a single ``*''
character was used to elide more than one field in the middle of the
name. See PLATFORM-SPECIFIC issues for a list of the system fonts.
 family pointsize ?stylelist?
A properly formed list whose first element is the desired font
family, whose second element is the desired pointsize, and
whose last optional element stylelist is itself a list of font
attributes. This format allows the user to easily specify a minimal set
of attributes and get reasonable behavior. Possible values for the
elements of stylelist are as follows:
normal bold roman italic
 X-font names (XLFD)
A fully specified XLFD is of the form
A ``*'' character may be used to skip individual fields that the user
does not care about. There must be exactly one ``*'' for each field
elided, except that the last six (or fewer) fields may be elided by a single
 option value ?option value ...?
A properly formed list of option-value pairs that specify
the desired attributes of the font, in the same format used when defining
a named font; see FONT OPTIONS below.
When font description font is used, the system attempts to parse the
description according to each of the above five rules, in the order specified.
Cases  and  must match the name of an existing named font or of a
system font. Cases , , and  are accepted on all
platforms and the closest available font will be used. In some situations
it may not be possible to find any close font (e.g., the font family was
a garbage value); in that case, some system-dependant default font is
chosen. If the font description does not match any of the above patterns,
an error is generated.
The following options are used by the font metrics command to query
font-specific data determined when the font was created. These properties are
for the whole font itself and not for individual characters drawn in that
font. In the following definitions, the ``baseline'' of a font is the
horizontal line where the bottom of most letters line up; certain letters,
such as lower-case ``g'' stick below the baseline.
The amount in pixels that the tallest letter sticks up above the baseline of
the font, plus any extra blank space added by the designer of the font.
The largest amount in pixels that any letter sticks down below the baseline
of the font, plus any extra blank space added by the designer of the font.
Returns how far apart vertically in pixels two lines of text using the same
font should be placed so that none of the characters in one line overlap any
of the characters in the other line. This is generally the sum of the ascent
above the baseline line plus the descent below the baseline.
Returns a boolean flag that is ``1'' if this is a fixed-width font,
where each normal character is the the same width as all the other
characters, or is ``0'' if this is a proportionally-spaced font, where
individual characters have different widths. The widths of control
characters, tab characters, and other non-printing characters are not
included when calculating this value.
The following options are supported on all platforms, and are used when
constructing a named font or when specifying a font using style  as
The case-insensitive font family name. Tk guarantees to support the font
families named Courier (a monospaced ``typewriter'' font), Times
(a serifed ``newspaper'' font), and Helvetica (a sans-serif
``European'' font). The most closely matching native font family will
automatically be substituted when one of the above font families is used.
The name may also be the name of a native, platform-specific font
family; in that case it will work as desired on one platform but may not
display correctly on other platforms. If the family is unspecified or
unrecognized, a platform-specific default font will be chosen.
The desired size of the font, in points. If a font cannot be displayed at the
specified pointsize, a nearby pointsize will be chosen. If the pointsize is
unspecified, a platform-dependant default pointsize will be chosen.
The nominal thickness of the characters in the font. The value
normal specifies a normal weight font, while bold specifies a
bold font. The closest available weight to the one specified will
be chosen. The default weight is normal.
The amount the characters in the font are slanted away from the
vertical. Valid values for slant are roman and italic.
A roman font is the normal, upright appearance of a font, while
an italic font is one that is tilted some number of degrees from upright.
The closest available slant to the one specified will be chosen.
The default slant is roman.
The value is a boolean flag that specifies whether characters in this
font should be underlined. The default value for underline is false.
The value is a boolean flag that specifies whether a horizontal line should
be drawn through the middle of characters in this font. The default value
for overstrike is false.
The following named system fonts are supported:
All valid X font names, including those listed by xlsfonts(1), are available.
system ansi device
systemfixed ansifixed oemfixed
Last change: 4.2
[ tcl8.0a1 | tk8.0a1 | X-ref ]
Copyright © 1989-1994 The Regents of the University of California.
Copyright © 1994-1996 Sun Microsystems, Inc.