title: How do I make my treeview fit the frame in my notebook in tkinter?
body: <p>I'm actually new to using python. I just wanted to ask if how am I going to be able to make my treeview fit/expand automatically on the frame inside a notebook widget without resorting to a fixed width and height for the treeview container (frame)? I'm not sure if what I'm doing wrong here. Here is my progress so far. Also tips on how I can improve my coding are greatly appreciated.</p>
  
  <p>Although I can make my treeview expand to its frame by uncommenting the line </p>
  
  <p>self.tabcpfailures.grid_propagate(0) and giving a fixed width and height to the frame which I'm avoiding.</p>
  
  <p>mainwindow.py</p>
  
  <pre><code>import tkinter as tk
  import tk_tooltip as ttp
  import menu
  from tkinter import ttk
  from tkinter import messagebox
  
  
  class MainWindow:
  
  def __init__(self, master):
  
      self.master = master
      self._menu_frame = None
      # Main GUI elements declaration
  
      self.frmnav = tk.Frame(self.master, bg="#182C61")
      self.menu_frame = tk.Frame(self.master, bg="green")
  
      self.btndaily = self.mn_create_navbutton(
          "D", "Daily Monitoring", menu.DailyMonitoring)
  
      # Main GUI elements styling
      self.master.title("DETE Tool")
      self.master.config(bg="white")
      self.master.geometry("{}x{}".format(self.master.winfo_screenwidth(),
                                          self.master.winfo_screenheight()))
      self.master.columnconfigure(1, weight=1)
      self.master.rowconfigure(0, weight=1)
  
      self.frmnav.grid(row=0, column=0, sticky="nsew")
  
      self.menu_frame.columnconfigure(0, weight=1)
      self.menu_frame.rowconfigure(0, weight=1)
      self.menu_frame.grid(row=0, column=1, sticky="nsew")
  
      self.btndaily.grid(row=0, column=0,
                         pady=(10, 0), padx=(5, 5))
  
      self.menu_frame.grid_propagate(0)
      self.btndaily.grid_propagate(0)
  
  def mn_create_navbutton(self, text, tooltip, menu_class):
  
      button_placeholder = tk.Frame(self.frmnav, width=50, height=50)
      button_placeholder.columnconfigure(0, weight=1)
      button_placeholder.rowconfigure(0, weight=1)
      nav_button = tk.Button(button_placeholder, text=text, bg="#e67e22", fg="white", font=("Roboto", 10, "bold"), relief="flat",
                             command=lambda: self.mn_switch_frame(menu_class))
      nav_button_tooltip = ttp.CreateToolTip(nav_button, tooltip)
      nav_button.grid(row=0, column=0, sticky="nesw")
  
      return button_placeholder
  
  def mn_center_window(self, screenwidth, screenheight):
  
      # Gets the requested values of the height and widht.
      self.screenwidth = screenwidth
      self.screenheight = screenheight
  
      windowWidth = self.master.winfo_reqwidth()
      windowHeight = self.master.winfo_reqheight()
  
      # Gets both half the screen width/height and window width/height
      positionRight = int(
          self.master.winfo_screenwidth() / 2 - windowWidth / 2)
      positionDown = int(
          self.master.winfo_screenheight() / 2 - windowHeight / 2)
  
      # Positions the window in the center of the page.
      return self.master.geometry("{}x{}+{}+{}".format(self.screenwidth, self.screenheight, positionRight, positionDown))
  
  def mn_switch_frame(self, menu_class):
  
      menu_new_frame = menu_class(self.menu_frame)
  
      if self._menu_frame is not None:
  
          self._menu_frame.destroy()
  
      self._menu_frame = menu_new_frame
  </code></pre>
  
  <p>menu.py</p>
  
  <pre><code>import tkinter as tk
  import tk_tooltip as ttp
  import db
  from tkinter import ttk
  from tkinter import messagebox
  
  class DailyMonitoring(tk.Frame):
  
  def __init__(self, master):
  
      super().__init__(master)
      self.master = master
  
      # DailyMonitoring GUI elements declaration
      self.tabparent = ttk.Notebook(self)
  
      self.tabcpfailures = tk.Frame(self.tabparent)
      self.tabparent.add(self.tabcpfailures, text="CP Failures")
      self.treecpfailures = CreateTreeView(
          self.tabcpfailures, *("id", "duedate", "workflowtype", "transactionid", "batchid", "jobid"))
  
      self.taberroredtasks = tk.Frame(self.tabparent)
      self.tabparent.add(self.taberroredtasks, text="Errored Tasks")
  
      # DailyMonitoring GUI elements styling
  
      self.grid(row=0, column=0, sticky="nsew")
      self.grid_propagate(0)
  
      self.tabparent.grid(row=0, column=0, sticky="nsew")
  
      self.tabcpfailures.grid_rowconfigure(0, weight=1)
      self.tabcpfailures.grid_columnconfigure(0, weight=1)
      #self.tabcpfailures.grid(row=0, column=0, sticky="nsew")
      #self.tabcpfailures.grid_propagate(0)
  
  class CreateTreeView:
  
  def __init__(self, master, *args):
  
      self.master = master
  
      self.treemenu = ttk.Treeview(self.master)
      self.treemenu["show"] = "headings"
      self.treemenu["columns"] = args
  
      for arg in args:
  
          self.treemenu.heading(arg, text="{}".format(arg))
  
      self.treemenu.grid(row=0, column=0, sticky="nsew")
  </code></pre>
  
  <p>How I want it to look like (this is by using a fixed width and height and uncommenting the <strong>self.tabcpfailures.grid_propagate(0)</strong>):</p>
  
  <p><a href="https://i.stack.imgur.com/391TH.png" rel="nofollow noreferrer">How I want it to look like</a></p>
  
  <p>How it looks like when I want to automatically expand frame inside the notebook so the the tree should also expand as well on the entire frame using <strong>self.tabcpfailures.grid(row=0, column=0, sticky="nsew")</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Y5Lbh.png" rel="nofollow noreferrer">How it looks like when using sticky=nsew</a></p>