How to remove Ttk Notebook Tab Dashed Line? (tkinter)


In order to work with Tabs and separate your workflow in an application, Tkinter provides a Notebook widget. We can use the Notebook widget to create Tabs in an application. Tabs are useful to isolate one particular frame or event from another.

Generally, Notebook widget can be configured and styled using the ttk themed widget. So, to style a Notebook widget, we pass TNotebook and TNotebook.Tab parameters in the configuration. If we click on a particular Tab, there may appear some rectangular dashed line which can be removed.


# Import the required library
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame
win = Tk()

# Create an instance of ttk
style = ttk.Style()

# Define Style for Notebook widget
style.layout("Tab", [('', {'sticky': 'nswe', 'children':
   [('Notebook.padding', {'side': 'top', 'sticky': 'nswe', 'children':
      [('Notebook.label', {'side': 'top', 'sticky': ''})],

# Use the Defined Style to remove the dashed line from Tabs
style.configure("Tab", focuscolor=style.configure(".")["background"])

# Create a Notebook widget
my_notebook= ttk.Notebook(win)

# Creating Tabs
tab1 = ttk.Frame(my_notebook)
my_notebook.add(tab1, text= "Tab 1")
tab2 = ttk.Frame(my_notebook)
my_notebook.add(tab2, text= "Tab2")

# Create a Label in Tabs
Label(tab1, text= "Hello, Howdy?",
   font = ('Helvetica 20 bold')).pack()
Label(tab2, text= "This is a New Tab Context",
   font = ('Helvetica 20 bold')).pack()


Executing the above code will display a window containing multiple tabs.

When we switch tabs from the window, it will display its content

Published on 08-Jun-2021 10:11:17