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
Here is an example which rotates an image using Python3:
For a Python2 version, see the revision history.
Here's unutbu's answer above, but in Python 3:
It took me a while to get this working, so I figured I would share.