title: What can cause unexpected tkinter widget resizing after frame resize?
body: <p>One thing that can do it is assigning weights to non existent columns and rows. Maybe users know of others?</p>
  
  <p>I recently had to track down this problem, and place it here in the hope it will be useful to others.
  After resizing your window frame, tkinter will not resize widgets if you have assigned a non zero weight to non existent columns. I ran into this situation where I had a dynamic UI which hid a panel, and replaced it with some buttons. For these buttons to resize properly, I did a columnconfigure and assigned weights of 1 to these extra columns. When the UI was restored, these buttons were removed, and we went back to one column. However the weights for these non existent columns still influenced the resizing as seen in the attached figure.</p>
  
  <p><a href="https://i.stack.imgur.com/buEqW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/buEqW.png" alt="after resizing the window frame, we don&#39;t want to see the pink"></a></p>
  
  <p>To solve the problem I reset the weights of these extra columns that I had set to 1 back to zero (even though these columns did not exist in the UI any more).</p>
  
  <p>Minimal code to illustrate the problem is shown below:</p>
  
  <p>The problem line is labelled <code># @@@@@@@ this is a problem</code></p>
  
  <pre><code>import tkinter as tk
  
  class frame_resize:
  
      def setupGUI(self):
          self._root = tk.Tk()
  
          self._font = 'helvetica 16'
  
          self._mainFrame = tk.Frame(self._root, bg='pink')
  
  
          self._label = tk.Label(self._mainFrame, 
              font=self._font,
              bg='sky blue',
              text='this is some text')
  
          self._mainButton = tk.Button(self._mainFrame, text='Press here',
                                font=self._font)
  
          # give weights so that widgets expand when outer frame expands
          tk.Grid.rowconfigure(self._root, 0, weight=1)
          tk.Grid.columnconfigure(self._root, 0, weight=1)
          tk.Grid.rowconfigure(self._mainFrame, 0, weight=1)
          tk.Grid.columnconfigure(self._mainFrame, 0, weight=1)
  
  
          # @@@@@@@ this is a problem, if we have no column 1
          tk.Grid.columnconfigure(self._mainFrame, 1, weight=1)
  
          #pop elemnts into grid
          self._mainFrame.grid(column=0, row=0, sticky='nsew')
          self._label.grid(column=0, row=0, sticky='nsew')
          self._mainButton.grid(column=0, row=1, sticky='nsew')
  
          self._root.mainloop()
  
  
  fr = frame_resize()
  fr.setupGUI()   
  </code></pre>