Home > Software engineering >  Tabcontrol tkinter inside another tabcontrol?
Tabcontrol tkinter inside another tabcontrol?

Time:03-03

I have a simple tabcontrol. How can I create another tabcontrol of the first Tab1? I mean inside Tab1 I want to create another tabcontrol with Tab 1.1, Tab 1.2, Tab 1.3. Thank you

import tkinter as tk                    
from tkinter import ttk
  
  
root = tk.Tk()
root.title("Tab Widget")
tabControl = ttk.Notebook(root)
  
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
  
tabControl.add(tab1, text ='Tab 1')
tabControl.add(tab2, text ='Tab 2')
tabControl.pack(expand = 1, fill ="both")
  
ttk.Label(tab1, 
          text ="Welcome to \
          GeeksForGeeks").grid(column = 0, 
                               row = 0,
                               padx = 30,
                               pady = 30)  
ttk.Label(tab2,
          text ="Lets dive into the\
          world of computers").grid(column = 0,
                                    row = 0, 
                                    padx = 30,
                                    pady = 30)
  
root.mainloop()

CodePudding user response:

Tabs can contain any widget you want. You can add a Notebook as a tab, or add another Frame, and put a Notebook inside the Frame.

tab3 = ttk.Notebook(tabControl)
tabControl.add(tab3, text = 'Tab 3')

tab3_1 = ttk.Frame(tab3)
tab3_2 = ttk.Frame(tab3)

tab3.add(tab3_1, text="Tab 3.1")
tab3.add(tab3_2, text="Tab 3.2")
  • Related