Python Forum
[Tkinter] Need help please properly putting tabs within a PanedWindow
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Need help please properly putting tabs within a PanedWindow
#1
Hello all.

I'm trying to get a PanedWindow to have tabs in it. I'm so close but I think my confusion with __init__ is getting me.

I have two examples that have me near, yet so far away.

This example here is closer to what I want, but not working out.

[Image: vvvv.png]
--------------------------------------------------------------------------------------------
The Entry widget loses its PanedWindow capability

class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
#        super(Frame, self).__init__()   
        tk.Frame.__init__(self, parent, *args, **kwargs)
#        ttk.Label.__init__(self, parent)        
        self.parent = parent

        self.w1 = tk.PanedWindow()  
        self.w1.pack(fill = tk.BOTH, expand = 1)  
 
        self.left = tk.Entry(self.w1, bd = 3)  
        self.w1.add(self.left)  

        self.w2 = tk.PanedWindow(self.w1, orient = tk.VERTICAL)  
        self.w1.add(self.w2)  
  
# -------------------------------------------------------------------------
        self.TAB_CONTROL = ttk.Notebook(self.w2)
        self.TAB1 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB1, text='Tab 1')
        self.TAB2 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB2, text='Tab 2')
        self.TAB_CONTROL.pack(expand=1, fill="both")
        ttk.Label(self.TAB1, text="This is Tab 1").grid(column=0, row=0, padx=10, pady=10)
#        ttk.Label(self.TAB2, text="This is Tab 2").grid(column=0, row=0, padx=10, pady=10)
# --------------------------------------------------------------------------

        tk.Entry(self.TAB1).grid(column=0, row=1, padx=10, pady=10) 
   #     self.e2 = tk.Entry(self.w2)  
  
  #      self.w2.add(self.e1)  
  #      self.w2.add(self.e2)  
  
 #       self.bottom = tk.Button(self.w2, text = "Add")  
 #       self.w2.add(self.bottom)  

if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack()
    root.mainloop()
-----------------------------------------------------------------------------------
This example here the PanedWindows work, though I want the right panal to be in the first tab, then subsequently put panedWindow on the second tab.

[Image: vvvv2.png]

class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
#        super(Frame, self).__init__()   
        tk.Frame.__init__(self, parent, *args, **kwargs)
#        ttk.Label.__init__(self, parent)        
        self.parent = parent

# -------------------------------------------------------------------------
        self.TAB_CONTROL = ttk.Notebook(self.parent)
        self.TAB1 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB1, text='Tab 1')
        self.TAB2 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB2, text='Tab 2')
        self.TAB_CONTROL.pack(expand=1, fill="both")
        ttk.Label(self.TAB1, text="This is Tab 1").grid(column=0, row=0, padx=10, pady=10)
        ttk.Label(self.TAB2, text="This is Tab 2").grid(column=0, row=0, padx=10, pady=10)
# ---------------------------------------------------------------------------
        self.w1 = tk.PanedWindow()  
        self.w1.pack(fill = tk.BOTH, expand = 1)  

        self.left = tk.Entry(self.w1, bd = 5)  
        self.w1.add(self.left)  

        self.w2 = tk.PanedWindow(self.w1, orient = tk.VERTICAL)  
        self.w1.add(self.w2)  
  
        self.e1 = tk.Entry(self.w2)  
        self.e2 = tk.Entry(self.w2)  
  
        self.w2.add(self.e1)  
        self.w2.add(self.e2)  
  
        self.bottom = tk.Button(self.w2, text = "Add")  
        self.w2.add(self.bottom)  

if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack()
    root.mainloop()
What I'm trying to get it looking like the first image, but with the panaledwindow in it working correctly.

Thanks for any help, being a noob sucks lol.

This might help show the vision, or perhaps confuse it more Idk lol.

[Image: vvvv3.png]
Reply
#2
Sorry to keep replying to my own threads. I keep working on this and when I think I have found the proper code for the placement I want, I'm getting errors.

This should be the code to theoretically get the layout I'm looking for:

import tkinter as tk
from tkinter import ttk

class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)     
        self.parent = parent

        self.w1 = tk.PanedWindow()  
        self.w1.pack(fill = tk.BOTH, expand = 1)  

        self.left = tk.Entry(self.w1, bd = 5)  
        self.w1.add(self.left)  

        self.w2 = tk.PanedWindow(self.w1, orient = tk.VERTICAL)  
        self.w1.add(self.w2)  

# -------------------------------------------------------------------------
        self.TAB_CONTROL = ttk.Notebook(self.w2)
        self.TAB1 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB1, text='Tab 1')
        self.TAB2 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB2, text='Tab 2')
        self.TAB_CONTROL.pack(expand=1, fill="both")
#        ttk.Frame(self.TAB1).grid(column=0, row=0, padx=10, pady=10)
#        ttk.Label(self.TAB2, text="This is Tab 2", width=100).grid(column=0, row=0, padx=10, pady=10)
# ---------------------------------------------------------------------------
        self.e1 = tk.Entry(self.TAB1)  
        self.e2 = tk.Entry(self.TAB1)  
  
        self.TAB1.add(self.e1)  
        self.TAB1.add(self.e2)  
  
        self.bottom = tk.Button(self.TAB1, text = "Add")  
        self.TAB1.add(self.bottom) 

if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack()
    root.mainloop()
But I'm getting this error here:

Error:
Traceback (most recent call last): File "c:/Users/Stryker/Desktop/py/NEW_TEMP.py", line 53, in <module> MainApplication(root).pack() File "c:/Users/Stryker/Desktop/py/NEW_TEMP.py", line 45, in __init__ self.TAB1.add(self.e1) AttributeError: 'Frame' object has no attribute 'add'
Reply
#3
import tkinter as tk
from tkinter import ttk

 
class MainApplication(tk.Frame):
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)     
        self.parent = parent
 
        self.w1 = tk.PanedWindow()  
        self.w1.pack(fill = tk.BOTH, expand = 1)  
 
        self.left = tk.Entry(self.w1, bd = 5)  
        self.w1.add(self.left)  
 
        self.w2 = tk.PanedWindow(self.w1, orient = tk.VERTICAL)  
        self.w1.add(self.w2)  
 
# -------------------------------------------------------------------------
        self.TAB_CONTROL = ttk.Notebook(self.w2)
        self.TAB1 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB1, text='Tab 1')
        self.TAB2 = ttk.Frame(self.TAB_CONTROL)
        self.TAB_CONTROL.add(self.TAB2, text='Tab 2')
        self.TAB_CONTROL.pack(expand=1, fill="both")
        ttk.Frame(self.TAB1).grid(column=0, row=0, padx=10, pady=10)
        ttk.Label(self.TAB1, text="This is Tab 1", width=100).grid(column=0, row=0, padx=10, pady=10)        
        ttk.Frame(self.TAB2).grid(column=0, row=0, padx=10, pady=10)
        ttk.Label(self.TAB2, text="This is Tab 2", width=100).grid(column=0, row=0, padx=10, pady=10)
# ---------------------------------------------------------------------------
        self.e1 = tk.Entry(self.TAB1) 
        self.e1.grid() 
        self.e2 = tk.Entry(self.TAB2)  
        self.e2.grid()    

   
        #self.bottom = tk.Button(self.TAB1, text = "Add")
        #self.TAB1.add(self.bottom) 
 
if __name__ == "__main__":
    root = tk.Tk()
    MainApplication(root).pack()
    root.mainloop()
check it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Found buttonstate in tabs MacTommu 4 1,947 Sep-22-2021, 05:56 PM
Last Post: deanhystad
  TabError: inconsistent use of tabs and spaces in indentation hobbyist 3 4,844 Jun-15-2021, 10:38 PM
Last Post: davide73_italy
Smile Panedwindow rfresh737 2 2,137 Apr-03-2021, 03:40 PM
Last Post: rfresh737
  [Tkinter] Vertical Tabs Alignment in Tkinter muhammadasim 2 5,913 Oct-05-2020, 08:40 AM
Last Post: Larz60+
  [PyQt] Drag items across tabs Alfalfa 5 4,687 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [Tkinter] Adding space between Notebook tabs Columbo 4 4,425 Jul-10-2019, 10:46 PM
Last Post: Columbo
  [Tkinter] How to get a tabs works exactly same as google chrome sarthak260 0 3,737 Mar-07-2019, 10:45 AM
Last Post: sarthak260
  [Tkinter] How to create multilple tabs in tkinter from different classes Rishav 5 18,180 Jul-11-2018, 11:59 AM
Last Post: CCChris91
  How to create mutiple tabs in tkinter using oops Rishav 2 6,823 Jul-12-2017, 04:43 PM
Last Post: Rishav
  seprating columns of an listbox item and putting them into different entry gray 2 4,204 Feb-26-2017, 12:53 PM
Last Post: gray

Forum Jump:

User Panel Messages

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