title: Python tkinter 8.5 - How do you change focus from main window to a pop up window?
body: <p>I'm new to tkinter and have a rather simple question. I would like to change focus from the first window, <code>root</code>,  to the <code>txt</code> window after it pops up. I would also like the "OK" button to be focused as well. Of course, the idea is for the user to just be able to hit enter when they see this error. I'm terribly confused after various attempts with focus(), focus_set(), and takefocus. I'm not finding the documentation for this particularly helpful. </p>
  
  <p>Below is my code:</p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  
  def close(self):
      self.destroy()
  
  def browse(*args):
      fileName = filedialog.askopenfilename()
      guiInputFile_entry.insert(0, fileName)
      return fileName
  
  def formatInput(*args):
      if guiInputFile.get()[-4:] != ".txt": #checks for correct file extension (.txt)
  
  
      txt = Tk()
      txt.title("Error")         
  
      txtFrame = ttk.Frame(txt, padding="30 30 30 30")            
      txtFrame.grid(column=0, row=0, sticky=(N,W,E,S))
      txtFrame.columnconfigure(0, weight=1)
      txtFrame.rowconfigure(0, weight=1)
  
      ttk.Label(txtFrame, text = "Please enter a .txt file.\n").grid(column=2, row=1)
      okButton = ttk.Button(txtFrame, text = "OK", command = lambda: close(txt)).grid(column=2, row=2)
      return
  
      root = Tk()
      root.title("Cost Load Formatter")
  
      mainframe = ttk.Frame(root, padding="3 3 12 12")
      mainframe.grid(column=0, row=0, sticky=(N,W,E,S))
      mainframe.columnconfigure(0, weight=1)
      mainframe.rowconfigure(0, weight=1)
  
      guiInputFile = StringVar()
  
      guiInputFile_entry = ttk.Entry(mainframe, width=100, textvariable=guiInputFile)
      guiInputFile_entry.grid(column=1, row=2, stick=(W,E))
  
      ttk.Label(mainframe, text="Please enter the full filepath of the .txt file you wish to format:").grid(column=1, row=1)
      browseButton = ttk.Button(mainframe, text="Browse...", underline=0, command=browse).grid(column=2, row=2, sticky=W)
      formatButton = ttk.Button(mainframe, text="Format", underline=0, command= lambda: formatInput(guiInputFile)).grid(column=1, row=3)
  
      for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
  
      guiInputFile_entry.focus()
  
      root.mainloop()
  </code></pre>
  
  <p>Thank you for any light you can shed.</p>