title: Python tkinter frame canvas resize
body: <p>I'm attempting to resize a canvas so the canvas fills the entire window when the window is resized by the user employing a 'click and drag' on the window edge, but I am not successful.  </p>
  
  <p>I have looked at the following other questions:</p>
  
  <p>Question #1 (previously posted, but not helping here)</p>
  
  <p>This one sent me in what I thought was the correct direction because I bind a Configure on canvas.  However, I get an error that " 'canvas' is not defined in FrameWidth."</p>
  
  <p><a href="https://stackoverflow.com/questions/29319445/tkinter-how-to-get-frame-in-canvas-window-to-expand-to-the-size-of-the-canvas">Tkinter: How to get frame in canvas window to expand to the size of the canvas?</a></p>
  
  <p>If I modify the function call and the function, then I get the error that "TypeError: FrameWidth() missing 1 required positional argument: 'canvas' "  The modification is </p>
  
  <pre><code>canvas.bind('&lt;Configure&gt;', self.FrameWidth(canvas))
  
  def FrameWidth(self, event, canvas):
  </code></pre>
  
  <p>Question #2 (previously posted, but not helping here)</p>
  
  <p>I also looked at this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/28631312/python-tkinter-scrollbar-shaky-scrolling">Python Tkinter Scrollbar Shaky Scrolling</a></p>
  
  <p>But this question is addressing an erratically behaving scrollbar.</p>
  
  <p>Question #3 (previously posted, but not helping here)</p>
  
  <p>I have also looked at this questions and put in weight=1, but that is not helping:</p>
  
  <p><a href="https://stackoverflow.com/questions/21766890/python-tkinter-frame-and-canvas-will-expand-horizontally-but-not-vertically-w">Python TKinter: frame and canvas will expand horizontally, but not vertically, when window is resized</a></p>
  
  <p>Any advice would be appreciated.</p>
  
  <p>Here's my MWE:</p>
  
  <pre><code>#!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  Created on Fri Nov  3 04:39:43 2017
  
  @author: davidc
  """
  
  import tkinter as tk
  
  
  class Selections(tk.Frame): 
      def __init__(self, *args, **kwargs):
          tk.Frame.__init__(self, *args, **kwargs)
  
          self.FifthLabelLeft = tk.Label(self,
                           text="""Riding""",
                           justify = tk.CENTER,
                           width=20,
                           padx = 10).grid(row=4, column = 0, pady=5)
  
          self.FifthLabelCenter = tk.Label(self,
                           text="""Winning Candidate""",
                           justify = tk.CENTER,
                           width=20,
                           padx = 10).grid(row=4, column = 1, pady=5)
  
          self.FifthLabelRight = tk.Label(self,
                           text="""Percent of Vote""",
                           justify = tk.CENTER,
                           width=10,
                           padx = 10).grid(row=4, column = 2, pady=5)
  
          mybox = tk.LabelFrame(self, padx=5, pady=4)
          mybox.grid(row=5, column=0, columnspan=3)
  
          canvas = tk.Canvas(mybox, borderwidth=5, background="#70ff33")
          frame = tk.Frame(canvas, background="#33f4ff")
          vsb = tk.Scrollbar(mybox, orient="vertical", command=canvas.yview)
          canvas.configure(yscrollcommand=vsb.set, width=450, heigh=30)       
  
          mybox.grid_columnconfigure(5,weight=1)
          mybox.grid_rowconfigure(5,weight=1)
          frame.grid_columnconfigure(5,weight=1)
          frame.grid_rowconfigure(5,weight=1)
  
          vsb.pack(side="right", fill="y")
          canvas.pack(side="left", fill="both", expand=True)
          canvas.create_window((4,4), window=frame, anchor="nw", tags="frame")
  
          # be sure that we call OnFrameConfigure on the right canvas
          frame.bind("&lt;Configure&gt;", lambda event: self.OnFrameConfigure(canvas))
          canvas.bind('&lt;Configure&gt;', self.FrameWidth)
  
          self.fillWindow(frame)
  
          self.QuitButton = tk.Button(self, 
                                      text="QUIT", 
                                      command=root.destroy, 
                                      padx=25, pady=0)
          self.QuitButton.grid(column = 0, columnspan=3)
  
  
      def fillWindow(self, frame): 
          PartyWinnersList = [['Some list of places', "Somebody's Name", 0.37448599960838064], 
                              ['A shorter list', 'Three Long Names Here', 0.52167817821240514],
                              ['A much longer, longer entry', 'Short Name', 0.41945832387008858]]
          placement = 2
          for i in PartyWinnersList:
              ShowYear = tk.Label(frame,
                                        text="""%s """ % i[0],
                                        width=20,
                                        )
              ShowYear.grid(row=placement, column = 0, sticky=tk.S)
              ShowSystem = tk.Label(frame,
                                        text="""%s """ % i[1],
                                        width=20,
                                        )
              ShowSystem.grid(row=placement, column = 1, sticky=tk.N)
              PercentVotes = i[2]*100
              ShowVotes = tk.Label(frame,
                                        text="""%3.1f""" % PercentVotes,
                                        width=10,
                                        )
              ShowVotes.grid(row=placement, column = 2, sticky=tk.N)
              placement += 1
  
      def FrameWidth(self, event):
          canvas_width = event.width
          canvas.itemconfig(self.canvas_frame, width = canvas_width)
  
      def OnFrameConfigure(self, canvas):
          canvas.configure(scrollregion=canvas.bbox("all"))
  
  
  if __name__ == "__main__": 
      root = tk.Tk()
      main = Selections(root)
      main.pack(side="top", fill="both", expand=True)
      root.mainloop()
  </code></pre>