我正在使用ttk.Combobox構建 GUI。我想知道其中任何文本的默認字體名稱和字體大小是什么。
uj5u.com熱心網友回復:
使用ttk.Style和tkinter.font。不知道有沒有更短的方法。
import tkinter as tk
from tkinter import ttk
from tkinter import font
root = tk.Tk() # font won't work before the Tk object is created
s = ttk.Style() # Create a Style object
combo_font_name = s.lookup( 'TCombobox', 'font' ) # Lookup the name of the default Combobox font
c_font = font.nametofont( combo_font_name ) # Find the font object for that font
c_font.actual() # Dictionary of attributes
# For my PC
# {'family': 'DejaVu Sans',
# 'size': 10,
# 'weight': 'normal',
# 'slant': 'roman',
# 'underline': 0,
# 'overstrike': 0}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483735.html
