Python Tkinter rotate image animation
Question: I have a PhotoImage that I created using PIL and then added to a TKinter
canvas. The image shows up fine. However, I can't get the PIL rotate function
to work correctly. Here is my code:

    
    
     #This works fine
     image = Image.open('img.png')
     canvas_image = ImageTk.PhotoImage(rotated_image)
     canvas_object = canvas.create_image(30+10*int(steps),250, image=canvas_image)
     canvas.pack()
    
     #this does not work
     canvas.delete(canvas_object)
     rotated_image = image.rotate(1)
     canvas_image = ImageTk.PhotoImage(rotated_image)
     canvas_object = canvas.create_image(30+10*int(steps),250, image=canvas_image)
     canvas.update()
    

However, the image just does not show up in this case. I want to be able to
animate the rotation of an image, but I can't even get a rotation to work at
all! Any suggestions are greatly appreciated.

Edit: correction, the rotation will not work after it's already been added to
the screen


Answer: 
    import Tkinter as tk
    from PIL import ImageTk
    from PIL import Image
    
    class SimpleApp(object):
        def __init__(self, master, filename, **kwargs):
            self.master = master
            self.filename = filename
            self.canvas = tk.Canvas(master, width=500, height=500)
            self.canvas.pack()
    
            self.update = self.draw().next
            master.after(1, self.update)
    
        def draw(self):
            image = Image.open(self.filename)
            angle = 0
            while True:
                tkimage = ImageTk.PhotoImage(image.rotate(angle))
                canvas_obj = self.canvas.create_image(
                    250, 250, image=tkimage)
                self.master.after_idle(self.update)
                yield
                self.canvas.delete(canvas_obj)
                angle += 10
                angle %= 360
    
    root = tk.Tk()
    app = SimpleApp(root, 'image.png')
    root.mainloop()
    

