Removing Ttk Notebook Tab Dashed Line

a 夏天 提交于 2019-11-29 14:43:28

You can remove this focus mark by altering the sub elements of tab widget. Ttk widgets are decomposed in subelements. The layout of these elements is described through layout method (or in a layout parameter of theme_create). Here is a command to remove layout marks (you can apply it directly to Tab, or any other derived theme), the commented part is what lead previously to drawing the focus (retrieved through style.layout("Tab"))

style.layout("Tab",
[('Notebook.tab', {'sticky': 'nswe', 'children':
    [('Notebook.padding', {'side': 'top', 'sticky': 'nswe', 'children':
        #[('Notebook.focus', {'side': 'top', 'sticky': 'nswe', 'children':
            [('Notebook.label', {'side': 'top', 'sticky': ''})],
        #})],
    })],
})]
)

A more hacky way could be to alter the color of this focus mark, for instance to draw it the same color as background

style.configure("Tab", focuscolor=style.configure(".")["background"])

On a Windows machine, if I create a theme and use "classic" as parent, the ugly dashed border is also not drawn.

style.theme_create( "Florina", parent="classic", settings={
    "TLabel": {"configure": {"background": BACKGROUND }},
    "TFrame": {"configure": {"background": BACKGROUND }},
    "TNotebook": {
        "configure": {"background": BACKGROUND, "tabmargins": [1, 5, 2, 0] }},
    "TNotebook.Tab": {
        "configure": {"background": DARKBG, "padding": [5, 2] },
        "map":       {"background": [("selected", BACKGROUND)],
                      "expand": [("selected", [1, 1, 1, 0])]
                      } } } )
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!