Apr-19-2020, 03:12 PM
You need to write the pages using a common API. This can be as simple an init and a way to get the page and maybe the title.
Notobook module
It should be pretty easy to automate filling the notebook with pages. You could put all the page modules in a folder and the notebook module would open scan the folder, import the page modules, and add the page. The contents of the pages themselves could be automated.
Notobook module
import tkinter as tk from tkinter import ttk import page1 import page2 class Paper(tk.Tk): def __init__(self): super().__init__() self.title("Daily Paper") self.notebook = ttk.Notebook(self) self.notebook.pack(fill='both') self.add_page(page1.Page1) self.add_page(page2.Page2) def add_page(self, page_cls): page = page_cls(self.notebook) self.notebook.add(page.frame, text=page.title) my_app = Paper() my_app.mainloop()Page module
import tkinter as tk headlines = ('Covid Cured', 'Economy Rebounds', 'Global Warming Reversed', 'World Peace') class Page1: def __init__(self, parent): self.title = 'Headlines' # Tab title in notebook self.frame = tk.Frame(parent) # Tab conents for i, text in enumerate(headlines): story = tk.Label(self.frame, text=text) story.grid(row=i, column=0)May as well have two pages:
import tkinter as tk sports = ('Hockey', 'Baseball', 'Soccer', 'Football', 'Basketball') class Page2: def __init__(self, parent): self.title = 'Sports' self.frame = tk.Frame(parent) for i, text in enumerate(sports): story = tk.Label(self.frame, text=text) story.grid(row=i, column=0)The notebook will automatically resize to fit the largest page, and the main window automatically resizes to fit the notebook.
It should be pretty easy to automate filling the notebook with pages. You could put all the page modules in a folder and the notebook module would open scan the folder, import the page modules, and add the page. The contents of the pages themselves could be automated.