title: How to wait for result from Tkinter TopLevel window before continuing?
body: <p>After a user clicks on a button, I want to create a new TopLevel window with suggestions and when user selects his/her suggestion on the toplevel window and clicks the button &quot;Done&quot; I want to destroy the toplevel window and pass the selected result to root window. This is what I want to achieve but until now I am not able to do it properly.</p>
  <p>I tried using <code>wait_window</code> on the toplevel window but that didn't work every time as sometimes it does not return anything or freezes indefinitely.</p>
  <pre><code>import tkinter as tk
  
  root = None
  BTN = None
  listbox = None
  selected = None
  SUGGESTIONS = [(0, &quot;level 1&quot;), (11, &quot;level 2&quot;), (23, &quot;level 3&quot;)]
  
  def select():
      global listbox, SUGGESTIONS, selected
  
      selected = listbox.get(tk.ANCHOR)
      for (idd, info) in SUGGESTIONS:
          if selected == f_info:
                  selected = idd
  
  def show_suggestions():
      global SUGGESTIONS, listbox
  
      win = tk.TopLevel()
      win.title(&quot;Select suggestion&quot;)
      win.geometry(&quot;400x400&quot;)
      
      listbox = tk.Listbox(win, height=20, width=40)
      listbox.pack(pady=15)
  
      self.btn = tk.Button(win, text=&quot;Confirm selection&quot;, command=select)
      self.btn.pack(pady=10)
  
      for (idd, info) in SUGGESTIONS :
          self.listbox.insert(tk.END, f_info) 
      
      #TODO: wait for selected suggestion and assign it to global variable selected
  
  def main():
      global root, BTN
      root = tk.Tk()
      root.title(&quot;Youtube to MP3&quot;)
      root.geometry(&quot;575x475&quot;)
  
      BTN = tk.Button(
          master=root,
          text=&quot;List suggestions&quot;,
          width=25,
          height=5,
          command=show_suggestions
      )
      BTN.pack(pady=15)
      
      root.mainloop()
  </code></pre>