Python Forum
[Tkinter] Need help please properly putting tabs within a PanedWindow - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Need help please properly putting tabs within a PanedWindow (/thread-22929.html)



Need help please properly putting tabs within a PanedWindow - JackMack118 - Dec-03-2019

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]


RE: Need help please properly putting tabs within a PanedWindow - JackMack118 - Dec-04-2019

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'



RE: Need help please properly putting tabs within a PanedWindow - balenaucigasa - Dec-08-2019

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