Sunday, September 8, 2013

How to get the name of a picture when it is clicked?

How to get the name of a picture when it is clicked?

I am going to make a Memory Puzzle in tkinter and I have problem with
mouse handle. I made 6 labels which show image (two of these are similar).
My problem is I don't now how to get the name of the image which is in a
label to compere with the secound clicked picture. my code is:
self.label1 = Label(self,..)
self.label2 = Label(self, width=100, height=100)
self.label3 = Label(self, width=100, height=100)
self.label4 = Label(self, width=100, height=100)
self.label5 = Label(self, width=100, height=100)
self.label6 = Label(self, width=100, height=100)
self.allLabel=[ self.label1 ,self.label2 , self.label3 ,
self.label4,self.label5 ,self.label6]
self.im=["a.png","b.png","c.png","a.png", "b.png", "c.png"]
for i in range (6):
self.allLabel[i]['image']= self.im[i]
for i in range (6):
self.allLabel[i].bind('<Button-1>',self.Event)
def Event(self,event):
if self.firstSelection==None:
self.firstSelection=(event.x, event.y) # save first click position
else:
self.secoundSelection=(event.x, event.y) # save second click position
# my problem is in the following code, how to compare two selected
pictures
if self.allLabel(self.firstSelection)==
self.allLabel(self.secoundSelection):
print ("similar pictures")
self.pack()
I now the following code is error:
if self.allLabel(self.firstSelection)==
self.allLabel(self.secoundSelection):
print ("similar pictures")
I wonder if somebody can help me with how to compare two selected pictures :)

No comments:

Post a Comment