This is an unofficial mirror of Tkinter reference documentation (based on Python 2.7 and Tk 8.5) created by the late John Shipman.
It was last updated in 2013 and is unmaintained. [More info]
Depending on your platform, there may be up to three ways to specify type style.
As a tuple whose first element is the font family,
followed by a size (in points if positive, in pixels
if negative), optionally followed by a string
containing one or more of the style modifiers
('Helvetica', '16') for a
16-point Helvetica regular;
'bold italic') for a 24-point Times bold
italic. For a 20-pixel Times bold font, use
('Times', -20, 'bold').
You can create a “font object” by
and using its
import tkFont font = tkFont.Font(
where the options include:
|The font family name as a string.|
The font height as an integer in points. To
get a font |
For example, to get a 36-point bold Helvetica italic face:
helv36 = tkFont.Font(family='Helvetica', size=36, weight='bold')
If you are running under the X Window System, you can
use any of the X font names. For example, the font
'-*-lucidatypewriter-medium-r-*-*-*-140-*-*-*-*-*-*' is a good fixed-width font for onscreen use. Use
the xfontsel program to
help you select pleasing fonts.
To get a list of all the families of fonts available on your platform, call this function:
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
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.
Returns the value of the given
Use this method to change one or more options on a
font. For example, if you have a
Font object called
titleFont, if you
size=18), that font will change to 18pt
Times and any widgets that use that font will
Returns a copy of a
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.
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:
|Number of pixels of height between the baseline and the top of the highest ascender.|
|Number of pixels of height between the baseline and the bottom of the lowest ascender.|
This value is |
|Number of pixels of height total. This is the leading of type set solid in the given font.|