Python Forum
[Tkinter] How to create multilple tabs in tkinter from different classes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to create multilple tabs in tkinter from different classes
#4
Hey, i've registered just to answer, fixed your code:

#!/usr/local/bin/python3
from tkinter import *
from tkinter import ttk
 
class App(Tk):
    def __init__(self,*args,**kwargs):
       Tk.__init__(self,*args,**kwargs)
       self.notebook = ttk.Notebook()
       self.add_tab()
       self.notebook.grid(row=0)
 
    def add_tab(self):
        tab = Area(self.notebook)
        tab2 = Volume(self.notebook) 
        self.notebook.add(tab,text="Tag")
        self.notebook.add(tab2,text="Tag2")
 
 
class Area(Frame):
   def __init__(self,name,*args,**kwargs):
       Frame.__init__(self,*args,**kwargs)
       self.label = Label(self, text="Hi This is Tab1")
       self.label.grid(row=1,column=0,padx=10,pady=10)
       self.name = name
 
class Volume(Frame):
   def __init__(self,name,*args,**kwargs):
       Frame.__init__(self,*args,**kwargs)
       self.label = Label(self, text="Hi This is Tab2")
       self.label.grid(row=1,column=0,padx=10,pady=10)
       self.name = name
 
my_app = App()
my_app.mainloop()
Not sure if it was really missing, or you've just forgot to copy it, but the mainloop() was missing from the end. Also, you only forgot to add 'self' from Label. This way you've put them under the main frame, instead of under their respective tab-frames. This way it works like you've designed it (i've tested it, works).
Reply


Messages In This Thread
RE: How to create multilple tabs in tkinter from different classes - by CCChris91 - Jul-10-2018, 11:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Help create scrollbar in chatbot with tkinter on python fenec10 4 1,632 Aug-07-2023, 02:59 PM
Last Post: deanhystad
  Found buttonstate in tabs MacTommu 4 2,059 Sep-22-2021, 05:56 PM
Last Post: deanhystad
  TabError: inconsistent use of tabs and spaces in indentation hobbyist 3 4,980 Jun-15-2021, 10:38 PM
Last Post: davide73_italy
  Tkinter & classes Heyjoe 6 3,106 Feb-13-2021, 09:17 PM
Last Post: Heyjoe
  [Tkinter] Vertical Tabs Alignment in Tkinter muhammadasim 2 6,125 Oct-05-2020, 08:40 AM
Last Post: Larz60+
  Tkinter: Create an homepage look like PeroPuri 8 6,032 Jun-26-2020, 12:57 AM
Last Post: menator01
  Create image on a Toplevel using tkinter ViktorWong 3 7,926 Jun-13-2020, 03:21 PM
Last Post: deanhystad
  [Tkinter] Need help please properly putting tabs within a PanedWindow JackMack118 2 3,416 Dec-08-2019, 03:02 PM
Last Post: balenaucigasa
  [PyQt] Drag items across tabs Alfalfa 5 4,874 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [Tkinter] Adding space between Notebook tabs Columbo 4 4,629 Jul-10-2019, 10:46 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

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