In a simple LightsOut game, when I click on a light I need to toggle the image on a button. I'm doing this with Tkinter, so I thought I'd just check and see what image is currently on the button (either 'on.gif' or 'off.gif') and set it to the other one, like this:
def click(self,x,y):
if self.buttons[x][y].image == self.on:
self.buttons[x][y].config(image=self.off)
self.buttons[x][y].image == self.off
else:
self.buttons[x][y].config(image=self.on)
self.buttons[x][y].image == self.on
This ends up always being True - I can turn a lgiht off, but never turn it back on. Did some research, realized that I should probably be using cmp:
def click(self,x,y):
if cmp(self.buttons[x][y].image,self.on) == 0:
self.buttons[x][y].config(image=self.off)
self.buttons[x][y].image == self.off
else:
self.buttons[x][y].config(image=self.on)
self.buttons[x][y].image == self.on
But that gave me the exact same result. Both self.on and self.off are PhotoImage objects. Aside from keeping a separate set of lists which tracks what type of light is in each position and redrawing them every click, is there a way to directly compare two PhotoImage objects like this?