GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • tkinter.colorchooser --- 顏色選擇對話框
  • Tkinter 對話框
  • 回報錯誤
  • 改進此頁面
  • 顯示原始碼
  • 顯示翻譯原始碼
  • 索引
  • 模組
  • Python
  • 3.15.2 documentation
  • Python 標準函式庫 (Standard Library)
  • 以 Tk 打造圖形使用者介面 (Graphical User Interfaces)
  • tkinter.font --- Tkinter 字型包裝器

This view

  • Original page
  • New address

GeezerVison is showing python.github.io — tkinter.font --- Tkinter 字型包裝器 — Python 3.15.2 說明文件

tkinter.font --- Tkinter 字型包裝器¶

原始碼:Lib/tkinter/font.py


tkinter.font 模組提供類別 Font,可以建立及使用已命名的字型。

不同的字重 (font weights) 以及傾斜 (slant) 是:

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 實例會被賦予一個的名字,也可以特指他們的字型家族 (font family)、字級 (size)、以及外觀設定。已命名字型是 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 - 如果存在的話,指向現有的已命名字型

額外的關鍵字選項(若已指定 font 則會忽略):

family - 字型家族,例如:Courier、Times
size - 字級
如果 size 是正數則會直譯成以點 (point) 為單位的字級。
如果 size 是負數則會變成絕對值
以像素 (pixel) 為單位的字級。
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)¶

回傳目前字型被格式化時,在特定顯示區域中文字所用的空間(以整數像素為單位)。若顯示區域沒有被指定,則會假定主程式視窗為顯示區域。

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 - 若字型為等寬 (fixed-width) 的則為 1,否則為 0

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

回傳可用字型家族名稱的元組。

tkinter.font.names(root=None)¶

回傳所有已定義字型名稱的元組。

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 參數。

© 版權所有 2001 Python Software Foundation.
此頁面採用 Python 軟體基金會授權條款第 2 版。
文件中的範例、應用技巧與其他程式碼額外採用了 Zero Clause BSD 授權條款。
更多訊息請見歷史與授權條款。

Python 軟體基金會是一家非營利法人。 敬請捐贈。

最後更新於 11月 11, 2026 (06:44 UTC)。 發現 bug?
以 Sphinx8.2.3建立。
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.