python - 如何确定 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'))
解决方案
改为使用my_style.lookup("W.TButton", "font")
。
推荐阅读
- ios - 处理可观察序列 RxSwift 上的循环样式事件
- jenkins - Jenkins - warnings-ng-plugin 与 android lint 报告集成
- flutter - 在 Flutter 中创建 Graphql 查询时出现语法错误
- node.js - 没有从 Dockerfile 中的 package.json 安装依赖项(RxJS)?
- regex - 正则表达式:不包含和前瞻
- css - React:如何为动态 SVG 创建可滚动容器?
- android - 使用 chrome 时 Firemonkey FMX.Android Intents 无法正常工作
- java - Spring MVC - 无法处理 MaxUploadSizeExceededException
- azure-devops - Angular CLI:TFS 构建步骤中的 ng 构建警告
- python - 无法将功能正确应用于 DataFrame 列