tkinter.font — Tkinter font wrapper¶
Source code: Lib/tkinter/font.py
The tkinter.font module provides the Font class for creating
and using named fonts.
The different font weights and slants are:
- class tkinter.font.Font(root=None, font=None, name=None, exists=False, **options)¶
- class tkinter.font.Font(
- root: tkinter.Misc | None = None,
- font: Font | _tkinter.Tcl_Obj | list[Any] | str | tuple[str] | tuple[str, int, list[str] | tuple[str, ...]] | tuple[str, int, Unpack[tuple[str, ...]]] | None = None,
- name: str | None = None,
- exists: bool = False,
- *,
- family: str = ...,
- size: int = ...,
- weight: Literal['bold', 'normal'] = ...,
- slant: Literal['italic', 'roman'] = ...,
- underline: bool = ...,
- overstrike: bool = ...,
(typeshed)
The
Fontclass represents a named font. Font instances are given unique names and can be specified by their family, size, and style configuration. Named fonts are Tk’s method of creating and identifying fonts as a single object, rather than specifying a font by its attributes with 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 if font is specified):
family - font family i.e. Courier, Timessize - font sizeIf size is positive it is interpreted as size in points.If size 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)¶
- actual( ) str
- actual( ) int
- actual( ) Literal['bold', 'normal']
- actual( ) Literal['italic', 'roman']
- actual( ) bool
- actual( ) tkinter.font._FontDict
- actual(*, displayof: tkinter.Misc | None = None) tkinter.font._FontDict
(typeshed)
Return the attributes of the font.
- cget(option)¶
- cget(option: Literal['family']) str
- cget(option: Literal['size']) int
- cget(option: Literal['weight']) Literal['bold', 'normal']
- cget(option: Literal['slant']) Literal['italic', 'roman']
- cget(option: Literal['overstrike', 'underline']) bool
- cget(option: str) Any
(typeshed)
Retrieve an attribute of the font.
- config(**options)¶
- config(
- *,
- family: str = ...,
- size: int = ...,
- weight: Literal['bold', 'normal'] = ...,
- slant: Literal['italic', 'roman'] = ...,
- underline: bool = ...,
- overstrike: bool = ...,
(typeshed)
Modify attributes of the font.
- measure(text, displayof=None)¶
- measure(text: str, displayof: tkinter.Misc | None = None) int
(typeshed)
Return amount of space the text would occupy on the specified display when formatted in the current font. If no display is specified then the main application window is assumed.
- metrics(*options, **kw)¶
- metrics( ) int
- metrics( ) bool
- metrics(*, displayof: tkinter.Misc | None = ...) tkinter.font._MetricsDict
(typeshed)
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)¶
- tkinter.font.families( ) tuple[str, ...]
(typeshed)
Return the different font families.