如何在 tkinter python 中删除 tabMenu 上的虚线

how to remove dotted line on tabMenu in tkinter python

如你所见,点击tabMenu后每个tabMenu都有虚线 如何删除这条虚线? 底部是源代码谢谢。

    from tkinter import *
    from tkinter import ttk

    tabposition = ttk.Style()
    tabposition.configure('TNotebook', sticky='w', tabposition='sw')
    
    style = ttk.Style()
    
    tabposition.configure("Tab", focuscolor=style.configure(".")["background"])
    
    notebook = ttk.Notebook(root, width=1450, height=910)
    notebook.pack(fill="y",expand=False)
    notebook.place(x=526)

    def newtab2():
        frame0 = Frame(root)
        notebook.add(frame0, text="First Input")

    addSheet = Button(root, text="Enter", command=newtab2, borderwidth=1)
    addSheet.place(x=10, y=159, width=41, height=41)

有几点要说:

  1. 当您要将框架添加到 ttk.Notebook 时,请将其用作框架的 master。在您的代码中,给出了 root

  2. 无需使用新的ttk.Style()。而是设置原来的布局 ttk.Style()

下面给出的是更正后的代码。请注意, ttk.Notebook 的高度是我更改的。您可以稍后更改它。

from tkinter import *
from tkinter import ttk
root=Tk()
tabposition = ttk.Style()
tabposition.configure('TNotebook', sticky='w', tabposition='sw')
notebook = ttk.Notebook(root, width=1450, height=510)
notebook.pack(fill="both",expand=1)
tabposition.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': ''})],
        #})],
    })],
})]
)
def newtab2():
    frame0 = Frame(notebook)
    notebook.add(frame0, text="First Input")
addSheet = Button(root, text="Enter", command=newtab2, borderwidth=1)
addSheet.place(x=10, y=159, width=41, height=41)
root.mainloop()