I have a tkinter GUI that displays an image, and I want to make a button that rotates it 90 degrees when I click it. I am using PIL, so I tried the rotate() function and all it does when I click it is scoot the image down the window. I have tried several other ways to rotate it and nothing seems to work. I am trying to build this rotate button within a class in my program. Does anyone know a good way to do this? Also, here's where I use rotate() where it's not actually rotating
class showIMG:
def __init__(self, frame):
self.frame = frame
self.button = Button(self.frame, text="Show", command=self.show)
self.button.pack()
self.button1 = Button(self.frame, text="Rotate", command=self.rotate)
self.button1.pack()
def show(self):
#image is created here from an array, which gives me a png, then I have:
self.img = Image.open("spec_img.png")
self.img1 = ImageTk.PhotoImage(self.img)
self.label = Label(window, image = self.img1)
self.label.pack()
def rotate(self):
self.img = Image.open("img.png")
self.img = self.img.rotate(90)
self.img1 = ImageTk.PhotoImage(self.img)
self.label = Label(window, image=self.img1)
self.label.pack()
I do see that I am reloading the image over and over again, but I'm not sure how I would do it such that a) I don't have to keep reloading it and b) it doesnt try to draw over itself