首页 > 解决方案 > 如何确定 tkinter 中 ttk.Button 使用的字体?

问题描述

我有一个 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'))

标签: pythontkinterttk

解决方案


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


推荐阅读