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
#2
(Jul-14-2017, 03:32 PM)Rishav Wrote: Why label of volume class is overwriting the label of area class in both tabs what's the solution to that help please

from tkinter import *
from tkinter import ttk

class App(Frame):
    def __init__(self,*args,**kwargs):
       Frame.__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(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(text="Hi This is Tab2")
       self.label.grid(row=1,column=0,padx=10,pady=10)
       self.name = name

my_app = App()

I think it has something to do with where you are placing each label as it seems you are telling them to be in the same place on screen and Area is in the same place as volume. Two things to try are to alter the row of one of the labels and the other is to use Area.lift after assigning tab2
I think one of these might help to see what is happening.
As I have said in another thread I haven't been using classes so I could be entirely wrong.
Reply


Messages In This Thread
RE: How to create multilple tabs in tkinter from different classes - by Barrowman - Jul-14-2017, 07:14 PM

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