Search code examples
pythontkintertabpaneltabmenu

how to remove dotted line on tabMenu in tkinter python


enter image description here

as you see image, each tabMenu has dotted line after tabMenu click how to remove this dotted line? bottom is source code thank you.

    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)


Solution

  • A few things to say:

    1. When you want to add a frame to a ttk.Notebook, use that as the master for the frame. In your code, it was given root

    2. No need to use new ttk.Style(). Instead, set the layout of the original ttk.Style()

    Given below is the corrected code. Note that the height of the ttk.Notebook is changed by me. You can change it later on.

    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()