About Lesson
In this TKinter Tutorial we are going to learn creating TKinter TabWidget, basically we are going to create a simple tabwidget in tkinter, we are not going to add any widget in the tab.
This is the complete code for this lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from tkinter import * from tkinter import ttk class Window(Tk): def __init__(self): super(Window, self).__init__() self.title("Tab Widget In TKinter") self.minsize(500,400) self.wm_iconbitmap("myicon.ico") tab_control = ttk.Notebook(self) tab1 = ttk.Frame(tab_control) tab_control.add(tab1, text = "Example One") tab2 = ttk.Frame(tab_control) tab_control.add(tab2, text = "Example Two") tab_control.pack(expan =1, fill = "both") window = Window() window.mainloop() |
First you need to create tab control and you can use ttk.NoteBook() for creating tab control.
1 |
tab_control = ttk.Notebook(self) |
Also we want to add our tab control in TKinter Frame.
1 |
tab1 = ttk.Frame(tab_control) |
After that you can use add() method for adding the tab.
1 |
tab_control.add(tab1, text = "Example One") |
In here we have used pack layout manager for the tab control.
1 |
tab_control.pack(expan =1, fill = "both") |
Run the complete code and we have nice tab widget in tkinter.