栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何更改标签标题框的大小和ttk笔记本标签的字体?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何更改标签标题框的大小和ttk笔记本标签的字体?

基于有关如何自定义笔记本标签的配置的答案,您可以将字体信息附加到创建的主题中,如下所示,以获取所需的字体类型:

import tkinter as tkfrom tkinter import ttkroot = tk.Tk()s = ttk.Style()s.theme_create( "MyStyle", parent="alt", settings={        "TNotebook": {"configure": {"tabmargins": [2, 5, 2, 0] } },        "TNotebook.Tab": {"configure": {"padding": [100, 10],       "font" : ('URW Gothic L', '11', 'bold')},}})s.theme_use("MyStyle")notebook = ttk.Notebook(root)f1 = tk.frame(notebook, bg='red', width=200, height=200)f2 = tk.frame(notebook, bg='blue', width=200, height=200)notebook.add(f1, text="frame 1" )notebook.add(f2, text="frame 2 longer" )notebook.grid(row=0, column=0, sticky="nw")root.mainloop()

另一种方法是直接配置笔记本的Tab样式。参见下面的代码。

import tkinter as tkfrom tkinter import ttkroot = tk.Tk()s = ttk.Style()s.configure('TNotebook.Tab', font=('URW Gothic L','11','bold') )notebook = ttk.Notebook(root)f1 = tk.frame(notebook, bg='red', width=200, height=200)f2 = tk.frame(notebook, bg='blue', width=200, height=200)notebook.add(f1, text="frame 1" )notebook.add(f2, text="frame 2 longer" )notebook.grid(row=0, column=0, sticky="nw")root.mainloop()

您必须注意使用

s.configure('TNotebook.Tab', font=('URW Gothic L','11','bold') )

之间的区别
s.configure('TNotebook', font=('URW Gothic L','11','bold'))
。前者更改笔记本的Tab小部件的字体,而后者更改笔记本的字体。

如果要配置选项卡的许多方面,则使用第一种方法。如果您只想更改笔记本选项卡的字体,则可以使用第二种方法。

使用

s.configure('.', font=('URW Gothic L','11','bold'))
表示所有ttk小部件字体都属于同一类型。如果这是您想要的,请执行此操作。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/647382.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号