Bottom Page

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.

İmage

--------------------------------------------------------------------------------------------
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.

İmage


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.

İmage
Quote
#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'
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyQt] Drag items across tabs Alfalfa 5 310 Sep-01-2019, 11:58 PM
Last Post: Alfalfa
  [Tkinter] Adding space between Notebook tabs Columbo 4 541 Jul-10-2019, 10:46 PM
Last Post: Columbo
  [Tkinter] How to get a tabs works exactly same as google chrome sarthak260 0 511 Mar-07-2019, 10:45 AM
Last Post: sarthak260
  [Tkinter] How to create multilple tabs in tkinter from different classes Rishav 5 9,196 Jul-11-2018, 11:59 AM
Last Post: CCChris91
  How to create mutiple tabs in tkinter using oops Rishav 2 2,735 Jul-12-2017, 04:43 PM
Last Post: Rishav
  seprating columns of an listbox item and putting them into different entry gray 2 1,847 Feb-26-2017, 12:53 PM
Last Post: gray

Forum Jump:


Users browsing this thread: 1 Guest(s)