tkinter.font --- Tkinter フォントラッパー

ソースコード: Lib/tkinter/font.py


tkinter.font モジュールは名前付きフォントを作成、使用するための Font クラスを提供します。

フォントの太さと傾きには次の種類があります:

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)

Font クラスは名前付きフォントを表します。 Font インスタンスには一意の名前が付き、ファミリー、サイズ、スタイルの設定で指定できます。 名前付きフォントは、使うたびに属性でフォントを指定する代わりに、1 つのオブジェクトとしてフォントを作成して識別する Tk の仕組みです。

バージョン 3.10 で変更: Two fonts now compare equal (==) only when both are Font instances with the same name belonging to the same Tcl interpreter.

引数:

font - フォントを指定するタプル (family, size, options)
name - フォントの一意の名前
exists - 真なら、self は既存の名前付きフォントを指します。

追加のキーワードオプション (font を指定した場合は無視されます):

family - font family, for example, Courier, Times
size - フォントサイズ
size が正なら、ポイント単位のサイズとして解釈します。
size が負なら、その絶対値を
ピクセル単位のサイズとして扱います。
weight - フォントの太さ (NORMAL、BOLD)
slant - ROMAN、ITALIC
underline - フォントの下線 (0 - なし、1 - 下線あり)
overstrike - フォントの取り消し線 (0 - なし、1 - 取り消し線あり)
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. The attributes are resolved on the display of the displayof widget, or the main application window if it is not specified.

cget(option)

フォントの属性を取得します。

configure(**options)

Modify one or more attributes of the font. With no arguments, return a dictionary of the current attributes.

config() is an alias of configure().

copy()

Return a distinct copy of the current font: a new named font with the same attributes but a different name, which can be reconfigured independently of the original. If the current font wraps a font description, the copy is instead a named font with its resolved attributes.

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.

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、それ以外は 0

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

Return a tuple of the names of the available font families.

tkinter.font.names(root=None)

Return a tuple of the names of all the defined fonts.

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

Return a 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.

バージョン 3.10 で変更: root 引数が追加されました。