tkinter.font
— Tkinter font wrapper¶
Source code:Lib/tkinter/font.py
Thetkinter.font
module provides theFont
class for creatingand using named fonts.
The different font weights and slants are:
- classtkinter.font.Font(root=None,font=None,name=None,exists=False,**options)¶
The
Font
class represents a named font.Font instances are givenunique names and can be specified by their family, size, and styleconfiguration. Named fonts are Tk’s method of creating and identifyingfonts as a single object, rather than specifying a font by its attributeswith each occurrence.arguments:
font - font specifier tuple (family, size, options)name - unique font nameexists - self points to existing named font if trueadditional keyword options (ignored iffont is specified):
family - font family i.e. Courier, Timessize - font sizeIfsize is positive it is interpreted as size in points.Ifsize is a negative number its absolute value is treatedas size in pixels.weight - font emphasis (NORMAL, BOLD)slant - ROMAN, ITALICunderline - font underlining (0 - none, 1 - underline)overstrike - font strikeout (0 - none, 1 - strikeout)- actual(option=None,displayof=None)¶
Return the attributes of the font.
- cget(option)¶
Retrieve an attribute of the font.
- config(**options)¶
Modify attributes of the font.
- copy()¶
Return new instance of the current font.
- measure(text,displayof=None)¶
Return amount of space the text would occupy on the specified displaywhen formatted in the current font. If no display is specified then themain application window is assumed.
- metrics(*options,**kw)¶
Return font-specific data.Options include:
- ascent - distance between baseline and highest point that a
character of the font can occupy
- descent - distance between baseline and lowest point that a
character of the font can occupy
- linespace - minimum vertical separation necessary between any two
characters of the font that ensures no vertical overlap between lines.
fixed - 1 if font is fixed-width else 0
- tkinter.font.families(root=None,displayof=None)¶
Return the different font families.
- tkinter.font.names(root=None)¶
Return the names of defined fonts.