1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import tkinter as tk
def Linked(a, b):
for tags in (a, b):
text.tag_config(tags, foreground="blue", underline=1)
text.tag_bind(tags, "<Enter>", lambda e: text.config(cursor="hand2"))
text.tag_bind(tags, "<Leave>", lambda e: text.config(cursor=""))
text.tag_bind(a, "<Button-1>", lambda e: text.see(text.tag_ranges(b)[0]))
text.tag_bind(b, "<Button-1>", lambda e: text.see(text.tag_ranges(a)[0]))
root = tk.Tk()
root.title("tkinter.Text sample : tag see")
text = tk.Text(root)
#
text.insert(tk.END, "(1)\n", 1)
for v in range(100):
text.insert(tk.END, "BLABLABLA\n")
text.insert(tk.END, "(1) Tag", 2)
Linked(1, 2)
#
text.pack()
tk.Button(root, text="Quit", command=root.destroy).pack(pady=5)
root.mainloop() |
Partager