我写了这个代码,这样当我按下图像时,图像就会改变颜色。问题是点击只起作用一次;当我再次点击时,什么也没发生。为什么
immagine1 = Label(root, image=photo1)
immagine1.place(x=20, y=20)
def su1(event):
print ("coordinate 1", event.x, event.y)
clickX1 = event.x
clickY1 = event.y
if (clickX1 >= 10 and clickX1 <= 275 and clickY1 >= 10 and clickY1 <= 320):
immagine1 = Label(root, image=photo2)
immagine1.place(x=20, y=20)
def giu1(event):
clickX1 = event.x
clickY1 = event.y
if (clickX1 >= 10 and clickX1 <= 275 and clickY1 >= 10 and clickY1 <= 320):
immagine1 = Label(root, image=photo1)
immagine1.place(x=20, y=20)
immagine1.bind("<Button-1>", su1)
immagine1.bind("<ButtonRelease-1>", giu1)
正确:
immagine1 = Label(root, image=photo1)
immagine1.place(x=20, y=20)
def su1(event):
print ("coordinate 1", event.x, event.y)
clickX1 = event.x
clickY1 = event.y
if (clickX1 >= 10 and clickX1 <= 275 and clickY1 >= 10 and clickY1 <= 320):
immagine1.configure(image=photo2)
def giu1(event):
clickX1 = event.x
clickY1 = event.y
if (clickX1 >= 10 and clickX1 <= 275 and clickY1 >= 10 and clickY1 <= 320):
immagine1.configure(image=photo1)
immagine1.bind("<Button-1>", su1)
immagine1.bind("<ButtonRelease-1>", giu1)
问题似乎是这样的:
在这里,您正在分配
immagine1
变量,因此您将丢失所做的绑定:相关问题 更多 >
编程相关推荐