如何确定 tkinter 中 ttk.Button 使用的字体?

How to determine the font being used by a ttk.Button in tkinter?

我有一个 ttk 按钮,我想知道它的字体。使用:my_button.cget('font') 给我 _tkinter.TclError: unknown option "-font"。好的,这意味着小部件本身不存储字体。所以我尝试使用 my_style.cget('font') 查询样式。那么结果就是AttributeError: 'Style' object has no attribute 'cget'.

这是一个代码片段。这次我尝试直接更改字体。我知道它是 calibri 但无法查询它:

my_style = ttk.Style()
my_style.configure('W.TButton', background='black',
                   font=('calibri', 10, 'bold', 'underline'), foreground='white')
print(my_style.cget('font'))

改用my_style.lookup("W.TButton", "font")

您还可以使用:

my_style.configure('W.TButton', 'font')