title: Making a function run code
body: <p>I am making a app with python and Tkinter. Say I added two buttons one for MAIN and one for NEWS when I press MAIN make the function mainthumsfun run and set the variables and after that run gui function with the new variables. How would I make that work?</p>
  
  <pre><code>import StringIO
  import Scraper
  import Tkinter as tk
  from PIL import Image, ImageTk
  
  root = tk.Tk()
  root.title('RazeTheWorld')
  
  maintumbs = Scraper.maintumbs()
  newstumbs = Scraper.newstumbs()
  
  def mainthumsfun():
      url0 = mainthumbs[0]
      url1 = mainthumbs[1]
      url2 = mainthumbs[2]
      url3 = mainthumbs[3]
  
  def newsthumbsfun():
      url0 = newsthumbs[0]
      url1 = newsthumbs[1]
      url2 = newsthumbs[2]
      url3 = newsthumbs[3]
  
  def gui():
      imgf1 = urllib.urlopen(url0)
      imgwr1 = StringIO.StringIO(imgf1.read())
      image1 = ImageTk.PhotoImage(Image.open(imgwr1))
      panel1 = tk.Label(root, image=image1)
      panel1.grid(row=0,column=0)
  
      imgf2 = urllib.urlopen(url1)
      imgwr2 = StringIO.StringIO(imgf2.read())
      image2 = ImageTk.PhotoImage(Image.open(imgwr2))
      panel2 = tk.Label(root, image=image2)
      panel2.grid(row=1,column=0)
  
      imgf3 = urllib.urlopen(url2)
      imgwr3 = StringIO.StringIO(imgf3.read())
      image3 = ImageTk.PhotoImage(Image.open(imgwr3))
      panel3 = tk.Label(root, image=image3)
      panel3.grid(row=2,column=0)
  
      imgf4 = urllib.urlopen(url4)
      imgwr4 = StringIO.StringIO(imgf4.read())
      image4 = ImageTk.PhotoImage(Image.open(imgwr4))
      panel4 = tk.Label(root, image=image4)
      panel4.grid(row=3,column=0)
  
  root.mainloop()
  </code></pre>