我将在tkinter制作一个记忆拼图,我的鼠标处理有问题。我做了6个显示图像的标签(其中两个是相似的)。我的问题是我现在不知道如何获得标签中的图像名称以与点击的图片进行对比。我的代码是:
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()
我现在以下代码是错误的:
if self.allLabel(self.firstSelection)== self.allLabel(self.secoundSelection):
print ("similar pictures")
我想知道是否有人可以帮助我比较两张选定的照片:)