title: Printing the results of a function into a tkinter message box?
body: <p>I've been coding for years and I have always been able to find an answer on google, until now. I cannot manage to make this work in any way.</p>
  
  <p>Before this I have several lists of different countries, and a dozen or so functions that just print stuff for the user, it is not relevant here. </p>
  
  <p>I use tkinter to create an input box where a user can type a country (input gets assigned to typedCountry). I then search for the country in each and every list in the mainProgram() function, and every time I find a list that matches I return another function. Everything works marvelously as it should, except I want mainProgram() to return the information to a tkinter GUI box and not the terminal. I've been fighting with it for hours and I cannot find a way to make it work, I am willing to take any advice, even changing the code significantly or using something other than tkinter would work just fine.</p>
  
  <pre><code>def mainProgram():
      typedCountry = e.get()
      Country = typedCountry.lower()
      print 'Your country is: ' + typedCountry + '\n'
      if Country in bannedCountries:
          banned(typedCountry)
      if Country in cpBannedCountries:
          cpBanned(typedCountry)
      if Country in skrillBannedCountries:
          skrillBanned(typedCountry)
      if Country in bacsCountries:
          Bacs(typedCountry)
      if Country in sepaCountries:
          sepa(typedCountry)
      if Country in eftCountries:
          eft(typedCountry)
      if Country in ltdCountries:
          ltd(typedCountry)
      if Country in marketsCountries:
          markets(typedCountry)
  
  master = Tk()
  e = Entry(master)
  e.pack()
  e.focus_set()
  var = mainProgram()
  
  def textBox():
      root = Tk()
      label = Message(root, textvariable=var)
      label.pack()
      root.mainloop()
  
  b = Button(master, text = "Search", command = mainProgram)
  b.pack()
  
  mainloop()
  </code></pre>
  
  <p>And here is the main code if you want it (if you want to run this in your end for example):</p>
  
  <pre><code>from tkinter import *
  import tkMessageBox
  
  
  
  bannedCountries = ['afghanistan','american samoa','belarus','brazil','burundi',
                      'central african republic','congo','cook islands','cote d\'ivoire',
                      'crimea','cuba','guam','iran','japan','liberia','libya','myanmar',
                      'new zealand','north korea','northern mariana islands','puerto rico',
                      'russia','singapore','somalia','south korea','sudan','syria','tokelau',
                      'turkey','ukraine','united states','vanuatu','virgin islands',
                      'western sahara','zimbabwe']
  
  cpBannedCountries = ['belarus','bosnia and herzegovina','burundi','cote d\'ivoire',
  'cuba','iran','iraq','kosovo','lebanon','liberia','macedonia','montenegro','myanmar',
  'nigeria','north korea','saint helena','somalia','sudan']
  
  skrillBannedCountries = ['angola','barbados','benin','burkina faso','cape verde',
  'comoros','djibouti','faroe islands','gambia','greenland','grenada','guyana','laos',
  'liechtenstein','macao','martinique','mongolia','namibia','niger','palau','samoa',
  'suriname','tajikistan','togo','trinidad and tobago','turkmenistan']
  
  bacsCountries = ["united kingdom"]
  
  eftCountries = ['australia']
  
  sepaCountries = ['austria','belgium','bulgaria','cyprus','czech republic','check',
  'denmark','estonia','finland','france','germany','greece','hungary','iceland',
  'ireland','italy','latvia','liechtenstein','lithuania','luxembourg','malta',
  'martinique','mayotte','monaco','netherlands','norway','poland','portugal',
  'romania','slovakia','slovenia','spain','sweden','switzerland','united kingdom']
  
  ltdCountries = ['austria','belgium','bulgaria','croatia','cyprus','czech republic',
  'denmark','estonia','finland','france','germany','greece','hungary','ireland',
  'italy','latvia','lithuania','luxembourg','malta','netherlands','poland','portugal',
  'romania','slovakia','slovenia','spain','united kingdom']
  
  marketsCountries = ['albania','algeria','andorra','angola','anguilla','armenia',
  'aruba','bahamas','bangladesh','barbados','belize','benin','bermuda','bhutan',
  'bonaire','bosnia','herzegovina','bosnia and herzegovina','botswana','brunei',
  'burkina faso','burma','cambodia','cameroon','cape verde','cayman islands',
  'chad','comoros','djibouti','equatorial guinea','eritrea','ethiopia','falkland islands (malvinas)',
  'faroe islands','gabon','gambia','ghana','greenland','grenada','guinea','guinea-bissau',
  'guyana','haiti','iceland','india','jamaica','jordan','kazakhstan','kenya',
  'kiribati','kosovo','kyrgyzstan','laos','lesotho','liechtenstein','macao',
  'macedonia','madagascar','malawi','malaysia','maldives','mali','marshall islands',
  'mauritania','mauritius','micronesia','mongolia','morocco','mozambique','namibia',
  'nauru','nepal','niger','nigeria','norway','pakistan','palau','papua new guinea',
  'philippines','rwanda','saint helena','saint kitts and nevis','saint lucia','saint vincent and the grenadines',
  'samoa','sao tome and principe','senegal','serbia','seychelles','sierra leone',
  'solomon islands','sri lanka','suriname','swaziland','tajikistan','tanzania','togo',
  'tonga','trinidad and tobago','tunisia','turkmenistan','turks and caicos islands','tuvalu',
  'uganda','uzbekistan','yemen','zambia']
  
  def banned(x):
      if 'kingdom' not in x:
          return 'Clients from %s are not able to open an account with FXCM' % x
      else:
          return
  
  def cpBanned(x):
      return "FXCM does not accept cards issued in %s" % x
  
  def skrillBanned(x):
      return "Clients from %s cannot use Skrill" % x
  
  def Bacs(x):
      return """Clients from %s can use BACS if their bank account is located in
  %s and both their bank account and their FXCM account is in GBP""" % (x, x)
  
  def sepa(x):
      return """Clients from %s can use SEPA if their bank account is located either in
  %s or in another European country, and both their bank account and their FXCM account is in EUR""" % (x, x)
  
  def eft(x):
      return """Clients from %s can use EFT if their bank account is located in
  %s, and both their bank account and their FXCM account is in AUD""" % (x, x)
      print "Clients from %s must open with FXCM AU" % x
  
  def ltd(x):
      return "Clients from %s must open with FXCM LTD" % x
  
  def markets(x):
      return "Clients from %s must open with FXCM Markets" % x
  
  def mainProgram():
      typedCountry = e.get() # This is the text you may want to use later
      Country = typedCountry.lower()
      print 'Your country is: ' + typedCountry + '\n'
      if Country in bannedCountries:
          banned(typedCountry)
      if Country in cpBannedCountries:
          cpBanned(typedCountry)
      if Country in skrillBannedCountries:
          skrillBanned(typedCountry)
      if Country in bacsCountries:
          Bacs(typedCountry)
      if Country in sepaCountries:
          sepa(typedCountry)
      if Country in eftCountries:
          eft(typedCountry)
      if Country in ltdCountries:
          ltd(typedCountry)
      if Country in marketsCountries:
          markets(typedCountry)
  
  master = Tk()
  e = Entry(master)
  e.pack()
  e.focus_set()
  var = mainProgram()
  
  def textBox():
      root = Tk()
      label = Message(root, textvariable=var)
      label.pack()
      root.mainloop()
  
  b = Button(master, text = "Search", command = mainProgram)
  b.pack()
  
  mainloop()
  </code></pre>