tkinter.font — Tkinter 글꼴 래퍼¶
소스 코드: Lib/tkinter/font.py
The tkinter.font module provides the Font class for creating
and using named fonts.
구별되는 글꼴 무게와 기울기는 다음과 같습니다:
- class tkinter.font.Font(root=None, font=None, name=None, exists=False, **options)¶
The
Fontclass represents a font used by Tk widgets. It either creates a new named font or refers to an existing font. A named font is Tk’s way of identifying a font as a single object that can be referred to by name and reconfigured in place, rather than respecifying its attributes at each use.With exists false (the default), a new named font is created. Its attributes are taken from the font description font if it is given, overridden by any keyword options. The new font is named name, or a generated unique name if name is omitted.
With exists true, an existing font is referred to instead of being created. If name is given, it is the name of the font, which is reconfigured by font and options if either is given. If name is omitted, the font description font is wrapped as is, without creating a named font, so that it is used without loss of precision by
actual(),measure()andmetrics(). In this case no keyword options are accepted, and thenameattribute is the description itself rather than a string.The font description font is a tuple of the family name, the size and zero or more styles, or any other form accepted by Tk, such as the name of a named font.
The keyword options are:
family - font family, for example, Courier, Timessize - 글꼴 크기size가 양수이면 포인트 단위의 크기로 해석됩니다.size가 음수이면 절댓값을픽셀 단위의 크기로 처리합니다.weight - 글꼴 강조 (NORMAL, BOLD)slant - ROMAN, ITALICunderline - 글꼴 밑줄 (0 - 없음, 1 - 밑줄)overstrike - 글꼴 취소선 (0 - 없음, 1 - 취소선)버전 3.10에서 변경: Two fonts now compare equal (
==) only when both areFontinstances with the same name belonging to the same Tcl interpreter.버전 3.16.0a0 (unreleased)에서 변경: A font description can now be wrapped without creating a new named font, and keyword options now override the attributes of the specified font.
- 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)¶
글꼴의 어트리뷰트를 가져옵니다.
참고
cget()andconfigure()operate on a named font and raiseTclErrorfor a wrapped font description. Useactual()to query the attributes of the latter.
- configure(**options)¶
Modify one or more attributes of the font. With no arguments, return a dictionary of the current attributes.
config()is an alias ofconfigure().
- 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 - 기준선(baseline)과 글꼴의 문자가 차지할 수 있는 가장 높은 점 사이의 거리
.
- descent - 기준선과 글꼴의 문자가 차지할 수 있는 가장 낮은 점 사이의 거리
.
- linespace - 줄 사이에 수직 겹침이 없음을 보장하는, 글꼴의 임의의 두 문자 간에 필요한 최소 수직 분리
.
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.