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

ttk styling “TNotebook.Tab” background and borderwidth not working

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

ttk styling “TNotebook.Tab” background and borderwidth not working

The point of the ttk theming support is to get the system provided theming
engine to draw the various elements that make up a Tk widget so that we match
the current UI’s look and feel. In the case of the Notebook Tab on Windows
Vista or above that means the ‘vsapi’ engine is being used to draw the
elements. The tab is an element and it’s look is provided by the Windows
theme. For this reason it doesn’t provide any way to modify the background as
that is done by selecting an alternative Windows theme.

However, what you can do is select an element from a different ttk theme that
does support changing the background style. This may not match closely in
other ways but you are already diverging from the system provided theme. The
way to completely control the look of your element is to create a new element
using the ‘image’ engine and provide images to be used to paint the element. A
simpler method is to borrow an element from one of the other themes. The
‘default’ theme provides support for specifying the color of the tab element
so we could borrow that by recreating the element and redefining the TNotebook
layout to use the new element.

# import the Notebook.tab element from the default themenoteStyler.element_create('Plain.Notebook.tab', "from", 'default')# Redefine the TNotebook Tab layout to use the new elementnoteStyler.layout("TNotebook.Tab",    [('Plain.Notebook.tab', {'children':        [('Notebook.padding', {'side': 'top', 'children': [('Notebook.focus', {'side': 'top', 'children':     [('Notebook.label', {'side': 'top', 'sticky': ''})], 'sticky': 'nswe'})],        'sticky': 'nswe'})],    'sticky': 'nswe'})])noteStyler.configure("TNotebook", background=COLOR_1, borderwidth=0)noteStyler.configure("TNotebook.Tab", background="green", foreground=COLOR_3,     lightcolor=COLOR_6, borderwidth=2)noteStyler.configure("Tframe", background=COLOR_1, foreground=COLOR_2, borderwidth=0)

The options made available depend on the theming engine in use to some extent
and the Windows theme is more restrictive than most because the drawing of the
elements is handed over to a third party. Extreme customisation is possible
but does require redefining the widget layout. This is mentioned in the
python ttk docs but
unless you know something about how ttk widgets are designed it’s not that
obvious what to do. The design intent is that you don’t make such extreme
customization but make your application conform to the users selected platform
look and feel. But the tools are available - just buried quite deeply. Here is
another link to a Tcl example that adds close buttons to the
tabs



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

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

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