ttk笔记本可以嵌套吗?

Can ttk notebooks be nested?

我正在尝试将一个 ttk 笔记本嵌套在另一个笔记本中,这样我就可以有多个标签级别。

想象一下上面的笔记本,每个食物组都有一个选项卡,并且在每个食物组选项卡中,都有一个用于该组食物示例的选项卡。选项卡式层次结构。

ttk笔记本可以吗?我没能找到处理这个问题的任何参考资料或示例。

看来这段代码应该可以工作。我没有收到任何错误,但看不到二级选项卡。任何帮助将不胜感激。

#import tkinter and ttk modules
from tkinter import *
from tkinter import ttk

#Make the root widget
root = Tk()

#Make the first notebook
nb1 = ttk.Notebook(root)
nb1.pack()
f0 = Frame(nb1)
f0.pack(expand=1, fill='both')

###Make the second notebook
nb2 = ttk.Notebook(f0)
nb2.pack()

#Make 1st tab
f1 = Frame(nb1)
#Add the tab to notebook 1
nb1.add(f1, text="First tab")

#Make 2nd tab
f2 = Frame(nb1)
#Add 2nd tab to notebook 1
nb1.add(f2, text="Second tab")

###Make 3rd tab
f3 = Frame(nb2)
#Add 3rd tab to notebook 2
nb2.add(f3, text="First tab")

###Make 4th tab
f4 = Frame(nb2)
#Add 4th tab to notebook 2
nb2.add(f4, text="Second tab")

root.mainloop()

已解决:

这是用符号简化的工作代码。希望其他人会觉得它很有启发性。本例使用 College Program>Terms>Courses

模型
#import tkinter and ttk modules
from tkinter import *
from tkinter import ttk

#Make the root widget
root = Tk()

#Make the first notebook
program = ttk.Notebook(root) #Create the program notebook
program.pack()

#Make the terms frames for the program notebook
for r in range(1,4):
    termName = 'Term'+str(r) #concatenate term name(will come from dict)
    term = Frame(program)   #create frame widget to go in program nb
    program.add(term, text=termName)# add the newly created frame widget to the program notebook
    nbName=termName+'courses'#concatenate notebook name for each iter
    nbName = ttk.Notebook(term)#Create the notebooks to go in each of the terms frames
    nbName.pack()#pack the notebook

    for a in range (1,6):
        courseName = termName+"Course"+str(a)#concatenate coursename(will come from dict)
        course = Frame(nbName) #Create a course frame for the newly created term frame for each iter
        nbName.add(course, text=courseName)#add the course frame to the new notebook 

root.mainloop()