我将在 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")
我想知道是否有人可以帮助我比较两张选定的图片:)