- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
# Import the required library from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win = Tk() win.geometry("700x350") # Create an instance of ttk style = ttk.Style() # Define Style for Notebook widget style.layout("Tab", [('Notebook.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) my_notebook.pack(expand=1,fill=BOTH) # 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() win.mainloop()
Output
Executing the above code will display a window containing multiple tabs.
When we switch tabs from the window, it will display its content
Advertisements