简体   繁体   English

如何更改 ttk.Button 中的字体大小?

[英]How to change font size in ttk.Button?

This is my problem, I was building an interface for a program, but for needs of the bosses, the font must be larger.这是我的问题,我是给一个程序做界面,但是为了老板的需要,字体一定要大一点。 I have changed the font size of every widget without any problem, but with the ttk.Buttons, I was unable to change it... I was reading that ttk.Button doesn't support the font attribute, but tk.Button supports it.我已经毫无问题地更改了每个小部件的字体大小,但是对于 ttk.Buttons,我无法更改它...我读到 ttk.Button 不支持字体属性,但 tk.Button 支持它. I tried with tk.Button and it works, but I don't like the graphic style of this tk.Button...我尝试使用 tk.Button 并且它有效,但我不喜欢这个 tk.Button 的图形样式......

Is there any way to change the font style and size of a ttk.Button, or changed the graphic style of the tk.Button to make similar to the ttk?有什么方法可以更改 ttk.Button 的字体样式和大小,或者更改 tk.Button 的图形样式以使其类似于 ttk?

Thanks to everyone!谢谢大家!

You have to use styles to customize ttk widgets. 您必须使用样式来自定义ttk小部件。

s = ttk.Style()
s.configure('my.TButton', font=('Helvetica', 12))
b = ttk.Button(mainframe, text='Press me', style='my.TButton',
command=foo)

The Above answer is correct and you can change the style for all of ttk widgets(for example font) you can change the root's style whose name is '.':上面的答案是正确的,您可以更改所有 ttk 小部件的样式(例如字体),您可以更改名称为“.”的根的样式:

s = ttk.Style()
s.configure('.', font=('Helvetica', 12))

After that, all of your ttk widgets's uses 'Helvetica' font in size '12'.之后,您所有的 ttk 小部件都使用大小为“12”的“Helvetica”字体。 The answer, derived from " https://tkdocs.com/shipman/ttk-style-layer.html "答案,来源于“ https://tkdocs.com/shipman/ttk-style-layer.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM