title: Why does Tkinter image not show up if created in a function?
body: <p>This code works:</p>
  
  <pre><code>import tkinter
  
  root = tkinter.Tk()
  canvas = tkinter.Canvas(root)
  canvas.grid(row = 0, column = 0)
  photo = tkinter.PhotoImage(file = './test.gif')
  canvas.create_image(0, 0, image=photo)
  root.mainloop()
  </code></pre>
  
  <p>It shows me the image.</p>
  
  <p>Now, this code compiles but it doesn't show me the image, and I don't know why, because it's the same code, in a class:</p>
  
  <pre><code>import tkinter
  
  class Test:
      def __init__(self, master):
          canvas = tkinter.Canvas(master)
          canvas.grid(row = 0, column = 0)
          photo = tkinter.PhotoImage(file = './test.gif')
          canvas.create_image(0, 0, image=photo)
  
  root = tkinter.Tk()
  test = Test(root)
  root.mainloop()
  </code></pre>