Debian Codegraph @

Doc/library/tkinter.font.rst

raw
1 :mod:`!tkinter.font` --- Tkinter font wrapper
2 =============================================
3
4 .. module:: tkinter.font
5 :synopsis: Tkinter font-wrapping class
6
7 **Source code:** :source:`Lib/tkinter/font.py`
8
9 --------------
10
11 The :mod:`!tkinter.font` module provides the :class:`Font` class for creating
12 and using named fonts.
13
14 The different font weights and slants are:
15
16 .. data:: NORMAL
17 BOLD
18 ITALIC
19 ROMAN
20
21 .. class:: Font(root=None, font=None, name=None, exists=False, **options)
22
23 The :class:`Font` class represents a named font. *Font* instances are given
24 unique names and can be specified by their family, size, and style
25 configuration. Named fonts are Tk's method of creating and identifying
26 fonts as a single object, rather than specifying a font by its attributes
27 with each occurrence.
28
29 arguments:
30
31 | *font* - font specifier tuple (family, size, options)
32 | *name* - unique font name
33 | *exists* - self points to existing named font if true
34
35 additional keyword options (ignored if *font* is specified):
36
37 | *family* - font family i.e. Courier, Times
38 | *size* - font size
39 | If *size* is positive it is interpreted as size in points.
40 | If *size* is a negative number its absolute value is treated
41 | as size in pixels.
42 | *weight* - font emphasis (NORMAL, BOLD)
43 | *slant* - ROMAN, ITALIC
44 | *underline* - font underlining (0 - none, 1 - underline)
45 | *overstrike* - font strikeout (0 - none, 1 - strikeout)
46
47 .. method:: actual(option=None, displayof=None)
48
49 Return the attributes of the font.
50
51 .. method:: cget(option)
52
53 Retrieve an attribute of the font.
54
55 .. method:: config(**options)
56
57 Modify attributes of the font.
58
59 .. method:: copy()
60
61 Return new instance of the current font.
62
63 .. method:: measure(text, displayof=None)
64
65 Return amount of space the text would occupy on the specified display
66 when formatted in the current font. If no display is specified then the
67 main application window is assumed.
68
69 .. method:: metrics(*options, **kw)
70
71 Return font-specific data.
72 Options include:
73
74 *ascent* - distance between baseline and highest point that a
75 character of the font can occupy
76
77 *descent* - distance between baseline and lowest point that a
78 character of the font can occupy
79
80 *linespace* - minimum vertical separation necessary between any two
81 characters of the font that ensures no vertical overlap between lines.
82
83 *fixed* - 1 if font is fixed-width else 0
84
85 .. function:: families(root=None, displayof=None)
86
87 Return the different font families.
88
89 .. function:: names(root=None)
90
91 Return the names of defined fonts.
92
93 .. function:: nametofont(name, root=None)
94
95 Return a :class:`Font` representation of a tk named font.
96
97 .. versionchanged:: 3.10
98 The *root* parameter was added.