from tkinter import *
from PIL import Image, ImageTk
import os
root = Tk()
text = Text(root, width=30, height=30)
text.pack()
text.insert(INSERT, "快点击这里啊<click>")
text.tag_add("come here", 1.7, 1.12)
text.tag_config("come here", foreground="blue", underline=True)
def enter(event):
text.config(cursor="arrow")
def leave(event):
text.config(cursor="xterm")
def click(event):
os.chdir("C:\\users\\david\\Desktop")
image = Image.open("qq.gif")
photo = ImageTk.PhotoImage(image)
text.image_create(END, image=photo)
text.tag_bind("come here", "<Enter>", enter)
text.tag_bind("come here", "<Leave>", leave)
text.tag_bind("come here", "<Button-1>", click)
mainloop()