title: "execfile" doesn't work properly
body: <p>I'm trying to make a launcher for my Python program with Tkinter. I used the execfile function, and fortunately it opened the target GUI. However, none of the buttons would work, and it would say the global variable most functions reference isn't defined.</p>
  
  <p>The code to launch the program:</p>
  
  <pre><code>def launch():
      execfile("gui.py")
  </code></pre>
  
  <p>That works. The base code for the target program:</p>
  
  <pre><code>from Tkinter import *
  gui = Tk()
  gui.title("This is a GUI")
  </code></pre>
  
  <p>EDIT:
  Example of a button:</p>
  
  <pre><code>def buttonWin():
      buttonWindow = Toplevel(gui)
      button = Button(buttonWindow, text = "Button", width = 10, command = None)
      button.pack()
  </code></pre>
  
  <p>When it references that 'gui' variable for Toplevel, it comes up with an error. I tried defining the 'gui' variable in the Launcher script, but that only caused the target script to open first, instead of the Launcher:</p>
  
  <pre><code>gui = Tk()
  launcher = Tk()
  launcher.title("Launcher")
  def launch():
      return execfile("gui.py")
  launchButton = Button(launcher, text = "Launch", width = 10, command = launch)
  </code></pre>
  
  <p>When I try pressing one of this program's buttons, I get a NameError:
  $NameError: Global variable 'gui' is not defined$
  Also this is in Python 2.7.5.
  Thank you anyone who answers, and sorry for any errors with the code blocks; I'm new.</p>