title: python, function that shows image in tkinter?
body: <p>i want to create a tkinter window and display the lena picture. I got a code that is working but i dont know how to make a function out of it. </p>
  
  <p>code:</p>
  
  <pre><code>import numpy
  import cv2
  from Tkinter import *
  from PIL import Image, ImageTk
  import scipy.misc
  
  #create root window
  root = Tk()
  root.geometry("600x600")
  
  #path to lena picture
  lena = "C:\lena.jpg"
  
  ##------------this as function----------------------------
  #convert lena.jpg into tkinter photo image
  image = Image.open(lena)
  photo = ImageTk.PhotoImage(image)
  
  #create canvas to display picture
  w = Canvas(root)
  w.create_image(0, 0, image = photo, anchor = "nw")
  w.pack(fill = BOTH, expand = YES)
  ##-------end:-this as function----------------------------
  
  
  #start root window
  root.mainloop()
  </code></pre>
  
  <p>I tried this function but it didnt open the lena picture...:</p>
  
  <pre><code>#create root window
  root = Tk()
  root.geometry("600x600")
  
  #path to lena picture
  lena = "C:\lena.jpg"
  
  
  def imgShow(img):
      ##------------this as function----------------------------
      #convert lena.jpg into tkinter photo image
      image = Image.open(img)
      photo = ImageTk.PhotoImage(image)
  
      #create canvas to display picture
      w = Canvas(root)
      w.create_image(0, 0, image = photo, anchor = "nw")
      w.pack(fill = BOTH, expand = YES)
      ##-------end:-this as function----------------------------
  
  ##use function with lena image path.
  ## doesnt work: window pops up but lena image is not shown
  imgShow(lena)
  
  #start root window
  root.mainloop()
  
  ## ErrorMessages?: No Error Message 
  </code></pre>
  
  <p>Do you know what i am doing wrong?</p>