I am using ttk.Combobox
to build a GUI. I want to know what's the default font name and font size of any text in this.
CodePudding user response:
Using ttk.Style
and tkinter.font
. I don't know if there's a shorter way.
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}