Python 如何使照片对鼠标点击作出响应?

Python 如何使照片对鼠标点击作出响应?,python,user-interface,tkinter,photo,Python,User Interface,Tkinter,Photo,嘿,我有一些照片是我用Tkinter玩的,我想知道是否有一种方法可以让我对鼠标点击做出反应?换句话说,我想创建一个程序,在这个程序中,我在画布上点击一张照片,然后让它在我的计算机上打开一个.xml文件 这里没有密码。感谢对此问题的所有输入。使用唯一字符串标记图像,然后使用标记绑定为单击事件注册处理程序 from Tkinter import * def image_clicked(event): print "an image on the canvas was clicked!"

嘿,我有一些照片是我用Tkinter玩的,我想知道是否有一种方法可以让我对鼠标点击做出反应?换句话说,我想创建一个程序,在这个程序中,我在画布上点击一张照片,然后让它在我的计算机上打开一个.xml文件


这里没有密码。感谢对此问题的所有输入。

使用唯一字符串标记图像,然后使用
标记绑定
为单击事件注册处理程序

from Tkinter import *

def image_clicked(event):
    print "an image on the canvas was clicked!"
    print "now opening xml file..."
    #todo: open xml file here

root = Tk()

canvas = Canvas(root, width=500, height=500)
canvas.pack()

canvas.create_rectangle([0,0,100,100], fill="blue", tag="opens_xml")
canvas.tag_bind("opens_xml", "<1>", image_clicked)

root.mainloop()
从Tkinter导入*
已单击def图像(事件):
打印“已单击画布上的图像!”
打印“正在打开xml文件…”
#todo:在此处打开xml文件
root=Tk()
画布=画布(根,宽度=500,高度=500)
canvas.pack()
canvas.create_矩形([0,0100100],fill=“blue”,tag=“opens_xml”)
标记绑定(“打开xml”,单击图像)
root.mainloop()

在上面的例子中,
image\u clicked
仅在单击蓝色矩形时调用。

谢谢!正是我想要的。