简体   繁体   English

删除 Ttk Notebook Tab 虚线

[英]Removing Ttk Notebook Tab Dashed Line

I'm trying to make a tkinter app that doesn't look like a tkinter app.我正在尝试制作一个看起来不像 tkinter 应用程序的 tkinter 应用程序。 I'm using a ttk Notebook, and the tabs have this little dotted line around the text when they're selected.我正在使用 ttk 笔记本,并且选项卡在被选中时在文本周围有这条小虚线。 It looks terrible, and I can't find a way to remove it using either styles or config.它看起来很糟糕,我找不到使用样式或配置删除它的方法。 Here's a screenshot to clarify:这是一个屏幕截图以澄清:

在此处输入图片说明

Edit for code (I don't think it'll be terribly helpful, since I'm actually just trying to remove a default style thing.):编辑代码(我认为这不会很有帮助,因为我实际上只是想删除默认样式的东西。):

Here is the notebook creation:这是笔记本的创建:

tabs = ttk.Notebook(mainframe, width=319, height=210, style=style.Notebook)
tabs.grid(column=0, row=1, sticky=('n', 'w', 'e', 's'))
tabs.columnconfigure(0, weight=1)
tabs.rowconfigure(0, weight=1)

Filling it in:填写:

tab1 = ttk.Frame(tabs)
tab1_frame = ttk.Frame(tab1, style=style.Frame)
tab1_frame.pack(anchor='center', expand=1, fill='both')
# stick some widgets in
progress = ttk.Progressbar(tab1_frame, orient="horizontal", length=300, mode="determinate")
progress.grid(column=1, row=1, columnspan=2, padx=style.padding, pady=style.padding)
progress['maximum'] = 1000
progress['value'] = 500
# More widgets
# Another tab
tab2 = ttk.Frame(tabs)
tab2_frame = ttk.Frame(tab2, style=style.Frame)
tab2_frame.pack(anchor='center', expand=1, fill='both')
# blah blah

Relevant styles:相关款式:

style_config = Style()
style_config.theme_use('default')

style_config.configure(self.Notebook,
    background=self.dark,
    borderwidth=0)

style_config.configure(self.Tab,
   background=self.dark,
   foreground='white',
   padding=self.padding,
   borderwidth=0)
style_config.map(self.Tab,
    background=[('selected', self.color1)])

You can remove this focus mark by altering the sub elements of tab widget. 您可以通过更改选项卡窗口小部件的子元素来删除此焦点标记。 Ttk widgets are decomposed in subelements . Ttk小部件在子元素中分解。 The layout of these elements is described through layout method (or in a layout parameter of theme_create ). 通过layout方法(或在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") ) 这是一个删除布局标记的命令(您可以直接将它应用于Tab或任何其他派生主题),注释部分是先前绘制焦点的原因(通过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. 在Windows机器上,如果我创建主题并使用“经典”作为父级,则也不会绘制丑陋的虚线边框。

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])]
                      } } } )

You can change the focus color using theme_create() :您可以使用theme_create()更改焦点颜色:

wthm = ttk.Style()
    
wthm.theme_create('wtheme', parent='default', settings={
       'TNotebook.Tab': {
           'configure': {'focuscolor':{
                             'configure':{
                                 '.':'<your_color>'}
                         }}
})

wthm.theme_use('wtheme')

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

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