title: RuntimeError: Too early to create image
body: <p>I am trying to create an image library and to call an image from that image library in <code>tkinter</code>.  But this code gives me an error:</p>
  
  <p>This is the image library file <code>img.py</code>:</p>
  
  <pre><code>from tkinter import *
  food_0001 = PhotoImage(file='food_0001.gif')
  food_0002 = PhotoImage(file='bg.gif')
  </code></pre>
  
  <p>This is the file intended to open images stored in <code>img.py</code>:</p>
  
  <pre><code>from tkinter import *
  import img
  
  window = Tk()
  window.title('image')
  canvas = Canvas(window, width = 800, height = 800)
  canvas.pack()
  canvas.create_image(0,0, anchor=NW, image=food_0001)
  
  window.mainloop()
  </code></pre>