接下來示範Notebook物件下擴增其他Notebook物件,首先
def init_notebookpage_1(self):
self.notebookpage_1_tab = tk.Frame(self.notebook)
self.notebook.add(self.notebookpage_1_tab, text="notebookpage_1")
在init_notebookpage_1中定義了另一個Notebook物件 self.notebook2
self.notebook2 = Notebook(self.notebookpage_1_tab)
self.notebook2.pack(side = tk.TOP,fill=tk.BOTH, expand=tk.YES)
self.init_notebookpage_2()
self.init_notebookpage_3()
並再增加另外兩個函式 self.init_notebookpage_2(), self.init_notebookpage_3(),兩者分別定義self.notebook2的其中兩分頁。
def init_notebookpage_2(self):
self.notebookpage_2_tab = tk.Frame(self.notebook2 )
self.notebook2.add(self.notebookpage_2_tab, text="notebookpage_2")
def init_notebookpage_3(self):
self.notebookpage_3_tab = tk.Frame(self.notebook2 )
self.notebook2.add(self.notebookpage_3_tab, text="notebookpage_3")
元件架構原理如下:
我們再練習多一點...
def __init__(self):
super().__init__()
self.title("This is a TEST!!!!")
self.geometry("240x200")
self.notebook = Notebook(self)
self.notebook.pack(side = tk.TOP,fill=tk.BOTH, expand=tk.YES)
self.init_notebookpage_1()
self.init_notebookpage_2()
def init_notebookpage_1(self):
self.notebookpage_1_tab = tk.Frame(self.notebook)
self.notebook.add(self.notebookpage_1_tab, text="notebookpage_1")
self.notebook1 = Notebook(self.notebookpage_1_tab)
self.notebook1.pack(side = tk.TOP,fill=tk.BOTH, expand=tk.YES)
self.init_notebookpage_5()
def init_notebookpage_2(self):
self.notebookpage_2_tab = tk.Frame(self.notebook)
self.notebook.add(self.notebookpage_2_tab, text="notebookpage_2")
self.notebook2 = Notebook(self.notebookpage_2_tab)
self.notebook2.pack(side = tk.TOP,fill=tk.BOTH, expand=tk.YES)
self.init_notebookpage_3()
self.init_notebookpage_4()
def init_notebookpage_3(self):
self.notebookpage_3_tab = tk.Frame(self.notebook2 )
self.notebook2.add(self.notebookpage_3_tab, text="notebookpage_3")
def init_notebookpage_4(self):
self.notebookpage_4_tab = tk.Frame(self.notebook2 )
self.notebook2.add(self.notebookpage_4_tab, text="notebookpage_4")
def init_notebookpage_5(self):
self.notebookpage_5_tab = tk.Frame(self.notebook1 )
self.notebook1.add(self.notebookpage_5_tab, text="notebookpage_5")