1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
:mod:`tkinter.font` --- Tkinter font wrapper
============================================
.. module:: tkinter.font
:platform: Tk
: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.
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 i.e. 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 attributes of the font.
.. method:: cget(option)
Retrieve an attribute of the font.
.. method:: config(**options)
Modify attributes of the font.
.. 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. If no display is specified then the
main application window is assumed.
.. method:: 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
.. function:: families(root=None, displayof=None)
Return the different font families.
.. function:: names(root=None)
Return the names of defined fonts.
.. function:: nametofont(name, root=None)
Return a :class:`Font` representation of a tk named font.
.. versionchanged:: 3.10
The *root* parameter was added.
|