tkinter.fontTkinter font wrapperTkinter字体包装器

Source code: Lib/tkinter/font.py


The tkinter.font module provides the Font class for creating and using named fonts.tkinter.font模块提供用于创建和使用命名字体的Font类。

The different font weights and slants are:不同的字体权重和倾斜为:

tkinter.font.NORMAL
tkinter.font.BOLD
tkinter.font.ITALIC
tkinter.font.ROMAN
classtkinter.font.Font(root=None, font=None, name=None, exists=False, **options)

The Font class represents a named font. Font类表示命名字体。Font instances are given unique names and can be specified by their family, size, and style configuration. Font实例具有唯一的名称,可以通过其族、大小和样式配置来指定。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.命名字体是Tk将字体创建和识别为单个对象的方法,而不是通过每次出现的属性指定字体。

arguments:

font - font specifier tuple (family, size, options)字体说明符元组(系列、大小、选项)
name - unique font name唯一字体名称
exists - self points to existing named font if true如果为true,则self指向现有命名字体

additional keyword options (ignored if font is specified):其他关键字选项(如果指定了font,则忽略):

family - font family i.e. Courier, Times字体系列,即Courier,Times
size - font size字体大小
If size is positive it is interpreted as size in points.如果size为正,则解释为以点为单位的大小。
If size is a negative number its absolute value is treated如果size为负数,则处理其绝对值
as size in pixels.大小以像素为单位。
weight - font emphasis (NORMAL, BOLD)字体强调(普通、粗体)
slant - ROMAN, ITALIC罗马、斜体
underline - font underlining (0 - none, 1 - underline)字体下划线(0-无,1-下划线)
overstrike - font strikeout (0 - none, 1 - strikeout)字体删除线(0-无,1-删除线)
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 display when formatted in the current font. 返回以当前字体格式化时文本在指定显示上所占的空间量。If no display is specified then the main 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如果字体为固定宽度,则为1,否则为0

tkinter.font.families(root=None, displayof=None)

Return the different font families.返回不同的字体系列。

tkinter.font.names(root=None)

Return the names of defined fonts.返回已定义字体的名称。

tkinter.font.nametofont(name, root=None)

Return a Font representation of a tk named font.返回tk命名字体的Font表示形式。

Changed in version 3.10:版本3.10中更改: The root parameter was added.已添加root参数。