tkinter.font — Tkinter font wrapper - Python 3.10.9 documentation 编辑

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:

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

The 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)
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

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.

Changed in version 3.10: The root parameter was added.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:57 次

字数:3433

最后编辑:6年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文