title: How do I update images on a Tkinter Canvas?
body: <p>I'm trying to make a script which will enable me to dynamically update an image object and then post the updated image to a Tkinter Canvas widget. The code here is prototype code, just to get the basics down. The aim here is to put a blue pixel on the image being displayed by the canvas, at the click location. </p>
  
  <p>Something very strange is going on here. I'm using the Wing IDE, and if I run this code through the debugger, with a breakpoint at any line in the <i>woohoo</i> function, and then continue execution after hitting the breakpoint, the code works exactly as expected- putting a blue pixel on the image. If I run the code normally, or through the debugger with no breakpoints, the image is never updated. This leads me to the conclusion that there is some internal wizardry going on which I haven't got much hope of understanding without aid.</p>
  
  <p>I'd really like to know the best way to go about this (or any way, I guess), and if someone could explain to me what's going on under the hood that'd be really cool. Thanks.</p>
  
  <pre><code>from Tkinter import *
  from PIL import Image, ImageTk
  
  def woohoo(event):
  
      original.putpixel((event.x,event.y),(0,0,255))
  
      newpic = ImageTk.PhotoImage(original)
      c.create_image((0,0),image=newpic, anchor="nw")
  
  
  main = Tk()
  c = Canvas(main, width=300, height=300)
  main.geometry("300x300+0+0")
  c.pack()
  
  original = Image.open("asc.bmp")
  picture = ImageTk.PhotoImage(original)
  c.create_image((0,0),image=picture, anchor="nw")
  
  c.bind("&lt;Button-1&gt;", woohoo)
  
  main.mainloop()
  </code></pre>