title: Auto-hiding scrollbar not showing as expected with tkinter pack() method
body: <p>I'm building the GUI for my Python app using tkinter, and I want the app to have a scrollbar that hides and shows when needed so that the window doesn't always have to be full size. I'm programming the code primarily on MacOS, and then Windows (because by the time I get something to work on MacOS getting it work on Windows is easy).</p>
  
  <p>The scrollbar in tkinter, by default, doesn't automatically hide itself when it's not needed, but I found some code <a href="https://stackoverflow.com/questions/41095385/autohide-tkinter-canvas-scrollbar-with-pack-geometry">in this stackoverflow question</a> that is supposed to do just that. I then made a test file so that I could fiddle around with the code without impacting my larger project. The code I pulled from stackoverflow wasn't quite what I needed, so I edited it in my test file. The code in the test file currently looks like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>import tkinter as tk
  
  
  class AutoScrollbar(tk.Scrollbar):
      """Create a scrollbar that hides iteself if it's not needed. Only
      works if you use the pack geometry manager from tkinter.
      """
      def set(self, lo, hi):
          if float(lo) &lt;= 0.0 and float(hi) &gt;= 1.0:
              self.pack_forget()
          else:
              if self.cget("orient") == tk.HORIZONTAL:
                  self.pack(fill=tk.X, side=tk.BOTTOM)
              else:
                  self.pack(fill=tk.Y, side=tk.RIGHT)
          tk.Scrollbar.set(self, lo, hi)
      def grid(self, **kw):
          raise tk.TclError("cannot use grid with this widget")
      def place(self, **kw):
          raise tk.TclError("cannot use place with this widget")
  
  
  #Creating the root, canvas, and autoscrollbar
  root = tk.Tk()
  vscrollbar = AutoScrollbar(root)
  canvas = tk.Canvas(root, yscrollcommand=vscrollbar.set)
  canvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
  vscrollbar.config(command=canvas.yview)
  
  #Creating the frame its contents
  frame = tk.Frame(canvas)
  label = tk.Label(frame, text="text", font=("Arial", "512"))
  label.pack()
  
  #Stuff that I don't quite understand
  canvas.create_window(0, 0, anchor=tk.NW, window=frame)
  frame.update_idletasks()
  canvas.config(scrollregion=canvas.bbox("all"))
  
  root.mainloop()
  </code></pre>
  
  <p>However, whenever I run the program, the scrollbar doesn't display on the far right side of the screen like I want to. Instead, it shows up in the bottom right corner and seems to extend a white block across the bottom of the app container. Additionally, the white block seems to count as part of the contents of the frame, which causes the scrollbar to show up early.</p>
  
  <p><strong>Large enough window, no scrollbar</strong>
  <img src="https://i.stack.imgur.com/kZGfa.png" alt="https://i.stack.imgur.com/kZGfa.png"></p>
  
  <p><strong>Slightly smaller window with scrollbar</strong>
  <img src="https://i.stack.imgur.com/BJhcm.png" alt="https://i.stack.imgur.com/BJhcm.png"></p>
  
  <p>The problem is even worse when I add the code to my application. The app container stays the same size, but the content is all scrunched into a much smaller box in the top left corner which expands when I pack in new widgets.</p>
  
  <p><strong>App homescreen before autoscroll implementation</strong>
  <img src="https://i.stack.imgur.com/LfWQo.png" alt="https://i.stack.imgur.com/LfWQo.png"></p>
  
  <p><strong>App homescreen after autoscroll implementation</strong>
  <img src="https://i.stack.imgur.com/ozmzi.png" alt="https://i.stack.imgur.com/ozmzi.png"></p>
  
  <p><strong>Expanded app homescreen after autoscroll implementation</strong>
  <img src="https://i.stack.imgur.com/PCuUt.png" alt="https://i.stack.imgur.com/PCuUt.png"></p>
  
  <p>I've been fiddling around for days. Any help is appreciated.</p>