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 26 27 28
| import tkinter as tk
import pickle
text = tk.Text()
texte = [("Et","Et","GN,","AP","FC"),("JH","je","GN,","AP","FC"),("me","me","GN,","AP","FC"),("KI","suis","GN,","AP","FC"),("OR","demandé","GN,","AP","FC")]
def on_click(e):
text_range = text.tag_prevrange("button", "@%d,%d"%(e.x,e.y))
print (text.get(*text_range))
def on_click2(e):
text_range = text.tag_prevrange("button1", "@%d,%d"%(e.x,e.y))
print (text.get(*text_range))
for mot2 in texte :
if mot2[0]==mot2[1] :
text.tag_config("button", background="yellow", foreground="blue", underline=1)
text.insert('end', ' ', "space", mot2[0], "button")
text.tag_bind("button", '<Button-1>', on_click)
else :
text.tag_config("button1", background="red", foreground="green", underline=1)
text.insert('end', ' ', "space", mot2[0], "button1")
text.tag_bind("button1", '<Button-1>', on_click2)
text.pack()
tk.mainloop() |
Partager