title: Python Tkinter dynamic window not working properly
body: <p>I'm trying to make a financial calculator for myself. Till now I didn't have any major problems, but now I'm stuck and can't figure out what's wrong.
  I'm new in this world so don't be mad about my lame coding skills haha!
  I made sqlite database with python and in this step I'm trying to pull one column and make button for each value dynamically. I succeed to make that step but my TopLevel window is not resizing how it should. That problem is caused because I want that TopLevel to be opened at same spot as root window, but I can't figure out where I'm making mistake.
  Here is my code, I deleted most of unimportant widgets and I made automatic input into db so you guys can check that dynamic button creation. Hope you understood what my problem is about if you need more explanation I will try my best.
  Most of code variables are on my language, hope that's not a problem and I don't know why indenting is messed up when I paste the code.</p>
  <pre><code>from tkinter import *
  import sqlite3
  
  conn = sqlite3.connect('Test.db')
  c = conn.cursor()
  c.execute('''CREATE TABLE IF NOT EXISTS OTPLATA_NA_RATE
           ([ID] INTEGER PRIMARY KEY,[Opis] text, [Iznos_rate] integer, [Broj_rata] text, [Datum_kupnje] text)''')
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;a&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;b&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;c&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;d&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;e&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  c.execute(&quot;INSERT INTO OTPLATA_NA_RATE VALUES (?, ?, ?, ?, ?);&quot;, (None, &quot;f&quot;, 500, &quot;2&quot;, &quot;2021-08-10&quot;))
  
  
  class FinancialCalc:
  def __init__(self, master):
      # Start window:
      self.master = master
      self.master.title(&quot;Kalkulator troška&quot;)
      self.master.geometry(&quot;300x300&quot;)
      self.master.resizable(False, False)
  
      self.otplata_na_rate_button = Button(master, text=&quot;Otplata na rate&quot;, width=15,
                                           command=self.otplata_na_rate_deiconify)
      self.otplata_na_rate_button.place(x=95, y=155)
  
      # TopLevel window
      self.onr_top = Toplevel()
      self.onr_top.title(&quot;Kalkulator troška&quot;)
      self.onr_top.withdraw()
  
  def otplata_na_rate_deiconify(self):
      # Otplata_na_rate TopLevel:
      self.master.withdraw()
      self.onr_top.deiconify()
      self.onr_top.protocol(&quot;WM_DELETE_WINDOW&quot;, lambda: (self.master.deiconify(), self.onr_top.withdraw()))
      # Pull data from db and creating dynamic buttons (depends how many items are in db)
      c.execute('SELECT Opis FROM OTPLATA_NA_RATE')
      lista_opisa_rata = list()
      for opis in c:
          lista_opisa_rata.append(opis[0])
      kolona = 0
      red = 0
      for opis in lista_opisa_rata:
          rata_button = Button(self.onr_top, text=opis, width=10)
          rata_button.grid(row=red, column=kolona, pady=5, padx=5)
          kolona += 1
          if kolona == 3:
              red += 1
              kolona = 0
  
      w = self.onr_top.winfo_width()
      h = self.onr_top.winfo_height()
      x = self.master.winfo_x()
      y = self.master.winfo_y()
      print(w, h)
      self.onr_top.geometry(&quot;%dx%d+%d+%d&quot; % (w, h, x, y))
  
  
   root = Tk()
   my_gui = FinancialCalc(root)
   root.mainloop()
  </code></pre>