Python Forum
Tkinter: multitab window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter: multitab window
#2
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
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.
Reply


Messages In This Thread
Tkinter: multitab window - by WizardMitMagi - Apr-19-2020, 11:37 AM
RE: Tkinter: multitab window - by deanhystad - Apr-19-2020, 03:12 PM
RE: Tkinter: multitab window - by WizardMitMagi - Apr-29-2020, 08:27 AM
RE: Tkinter: multitab window - by deanhystad - Apr-29-2020, 02:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 529 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Tkinter multiple windows in the same window tomro91 1 861 Oct-30-2023, 02:59 PM
Last Post: Larz60+
  Centering and adding a push button to a grid window, TKinter Edward_ 15 4,864 May-25-2023, 07:37 PM
Last Post: deanhystad
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,920 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  [Tkinter] Background inactivity timer when tkinter window is not active DBox 4 2,934 Apr-16-2022, 04:04 PM
Last Post: DBox
  why my list changes to a string as I move to another window in tkinter? pymn 4 2,584 Feb-17-2022, 07:02 AM
Last Post: pymn
  [Tkinter] Tkinter Window Has no Title Bar gw1500se 4 2,869 Nov-07-2021, 05:14 PM
Last Post: gw1500se
  "tkinter.TclError: NULL main window" Rama02 1 5,870 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  function in new window (tkinter) Dale22 7 5,170 Nov-24-2020, 11:28 PM
Last Post: Dale22
  Scrollable big image in a window (TKinter) Prospekteur 3 4,506 Sep-14-2020, 03:06 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020