我正在尝试将一个 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()
已解决:
这是使用符号简化的工作代码。希望其他人会发现它有启发性。本示例使用大学课程>术语>课程
的模型#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()