The problem was caused by the fact that the
object was being garbage collected after the
method completed, so the canvas appeared blank. Adding something like the extra line below holds it in place.
img=PhotoImage(master = canvas, width=WIDTH, height=HEIGHT)
canvas.create_image((WIDTH/2, HEIGHT/2), image=img, state="normal")
canvas.theimage = img