title: Python run script when Tkinter button pressed
body: <p>I am trying to make it so that the variable <code>fpl</code> is set when the button (command submit) is used. The problem is, it runs through the entire thing before the user has hit the button. How do i make it so the script beginning?</p>
  
  <pre><code>#Convert string to list
  fpl = fpl.replace(" " , ".")
  </code></pre>
  
  <p>Is only run once the user has pressed the button? Rest of the code below.</p>
  
  <pre><code>import json
  from tkinter import *
  
  def submit():
      fpl = entry.get()
  
  window = Tk()
  window.title ("Infinite FMS")
  
  Label (window, text="Enter your flight plan 
  here:").grid(row=0,column=0,sticky=W)
  
  entry = Entry(window, width = 75, bg = "light blue")
  entry.grid(row=1,column=0,sticky=W)
  
  Button (window, text="Submit", 
  command=submit).grid(row=2,column=0,sticky=W)
  
  output = Text(window,width=75,height=6,background="light 
  blue")
  output.grid(row=3,column=0,sticky=W)
  
  #Convert string to list
  fpl = fpl.replace(" " , ".")
  
  "[" + fpl + "]"
  
  fpllist = fpl.split(".")
  #Length of fpllist
  fpllen = len(fpllist)
  
  #Loop through the flight plan missing first and last 
  entries
  n = 1
  Invalid = []
  while n &lt; fpllen - 1:
      #Check for item in file
      searchTerm = (fpllist[n])
      searchTermF = "\'Name\': \'" + searchTerm + "\'"
      searchTermV = "\'identifier\': \'" + searchTerm + "\'"
      file = open('mydirectory', 'r')
      data1 = json.load(file)
      file.close()
      file = open('mydirectory', 'r')
      data2 = json.load(file)
      file.close()
      if searchTermF in str(data1):
          Validity = "Your route is valid!"
          n = n + 1
      elif searchTermV in str(data2):
          Validity = "Your route is valid!"
          n = n + 1
      else:
           Validity = "Your route is invalid!\nInvalid 
  waypoints:"
      Invalid.append(searchTerm)
      n = n + 1                    
  if len(Invalid) == 0:
      print (Validity , ', '.join(Invalid))
  else:
      Validity = "Your route is invalid!\nInvalid 
  waypoints:"
      print (Validity , ', '.join(Invalid))
  
  output.delete(0.0, END)
  output.insert(END, (Validity , ', '.join(Invalid)))
  </code></pre>