My objective is to change the text of label widget when the mouse move over the label.For one label i would do something like this:
import Tkinter as tk
def fun1(event):
label.config(text="Haha")
def fun2(event):
label.config(text="Label1")
root=tk.Tk()
label=tk.Label(root,text="Label1")
label.grid(row=1,column=1)
label.bind("<Enter>", fun1)
label.bind("<Leave>", fun2)
root.mainloop()
But now, i have a bunch of labels which is generated by for loop and a list which contains the text that i want to change.
mylist=['a','b','c','d','e']
for i in range(5):
tk.Label(root,text="Label"+str(i)).grid(row=i+1,column=1)
This will generate 5 labels with numbers. Is it possible to add mouse over event for each individual label so that when i mouse over on the label 1, it changes to 'a', when i mouse over to label 2, it changes to 'b', etc? FYI, the number of items in the mylist will always be the same with the number used in for loop.