cpython/Doc/library/tkinter.font.rst
Serhiy Storchaka 33b9f75c58
[3.13] gh-86726: Document the full public API of tkinter (GH-151579) (GH-151650) (GH-151653)
Replace the previously sparse reference documentation with full coverage of
the public API of the tkinter package, written from the Tcl/Tk manual pages,
the existing documentation and the module docstrings.

* Doc/library/tkinter.rst gains a "Reference" section documenting every public
  class, method, function and constant of the core module -- the widgets, the
  Misc, Wm, Pack, Place, Grid, XView and YView mix-ins, the Variable and image
  classes, the module-level functions and the symbolic constants.
* Doc/library/tkinter.ttk.rst, dialog.rst, tkinter.font.rst and the other
  module pages document their remaining classes, methods and functions.

The descriptions are Python-oriented (correct return types -- tuples rather
than Tcl lists, booleans, integers, None on cancellation, and so on) and were
checked against the Tcl/Tk 9.1 manual pages and the implementation.

versionadded, versionchanged and deprecated directives are added for the
public API, determined from the git history relative to Python 3.0: the
tkinter.ttk module (3.1); the Text, Wm, Menu and Misc methods exposing Tk 8.5
features (3.3); and the many later additions and behavior changes up to 3.15.
The Tk version required by features added after Tk 8.6 is noted as well.  The
bundled Tcl/Tk version is updated to 9.0 and the manual-page links point at
the tcl9.0 reference.

--------
(cherry picked from commit 8b270b72a2)





* gh-86726: Adjust tkinter docs for the 3.14 backport

Remove documentation of API added only in 3.15 (the grid_content/
pack_content/place_content aliases, Text.search_all, the search
nolinestop/strictlimits parameters and Event.user_data/detail), date the
wm_attributes positional-argument deprecation to 3.13, and update the
bundled Tcl/Tk version to 8.6.



---------
(cherry picked from commit 1141d294ee)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-06-18 13:32:37 +00:00

116 lines
3.9 KiB
ReStructuredText

:mod:`!tkinter.font` --- Tkinter font wrapper
=============================================
.. module:: tkinter.font
:synopsis: Tkinter font-wrapping class
**Source code:** :source:`Lib/tkinter/font.py`
--------------
The :mod:`tkinter.font` module provides the :class:`Font` class for creating
and using named fonts.
The different font weights and slants are:
.. data:: NORMAL
BOLD
ITALIC
ROMAN
.. class:: Font(root=None, font=None, name=None, exists=False, **options)
The :class:`Font` class 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.
.. versionchanged:: 3.10
Two fonts now compare equal (``==``) only when both are :class:`Font`
instances with the same name belonging to the same Tcl interpreter.
arguments:
| *font* - font specifier tuple (family, size, options)
| *name* - unique font name
| *exists* - self points to existing named font if true
additional keyword options (ignored if *font* is specified):
| *family* - font family, for example, Courier, Times
| *size* - font size
| If *size* is positive it is interpreted as size in points.
| If *size* is a negative number its absolute value is treated
| as size in pixels.
| *weight* - font emphasis (NORMAL, BOLD)
| *slant* - ROMAN, ITALIC
| *underline* - font underlining (0 - none, 1 - underline)
| *overstrike* - font strikeout (0 - none, 1 - strikeout)
.. method:: actual(option=None, displayof=None)
Return the actual attributes of the font, which may differ from the
requested ones because of platform limitations.
With no *option*, return a dictionary of all the attributes; if *option*
is given, return the value of that single attribute.
.. method:: cget(option)
Retrieve an attribute of the font.
.. method:: config(**options)
:no-typesetting:
.. method:: configure(**options)
Modify one or more attributes of the font.
With no arguments, return a dictionary of the current attributes.
:meth:`config` is an alias of :meth:`!configure`.
.. method:: copy()
Return new instance of the current font.
.. method:: measure(text, displayof=None)
Return amount of space the text would occupy on the specified display
when formatted in the current font, as an integer number of pixels.
If no display is specified then the main application window is assumed.
.. method:: metrics(*options, **kw)
Return font-specific data.
With no options, return a dictionary mapping each metric name to its
integer value; if one option name is given, return that metric's value as
an integer.
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
.. function:: families(root=None, displayof=None)
Return a tuple of the names of the available font families.
.. function:: names(root=None)
Return a tuple of the names of all the defined fonts.
.. function:: nametofont(name, root=None)
Return a :class:`Font` representation of the existing named font *name*.
*root* is the widget whose Tcl interpreter owns the font; if omitted, the
default root window is used.
.. versionchanged:: 3.10
The *root* parameter was added.