I’m trying to make a script where there are for example 9 widgets (Buttons, Labels…) and I want when I click and hold on any widget and I drag over another widget, both of widgets to be recolored (resp. all the widgets I dragged over), until I release the mouse button.
from Tkinter import *
root = Tk()
def recolor(event):
global ButtonList
event.widget.config(bg="red")
return
ButtonList=["b0","b1","b2","b3","b4","b5","b5","b6","b7","b8"]
i = 0
while i < 9:
ButtonList[i] = Label(root, text = i, width = 4, height = 2)
ButtonList[i].grid(row = i%3, column = i/3)
ButtonList[i].bind("<Enter>", recolor)
i += 1
root.mainloop()
This script only recolors the widget that I clicked on and after releasing the button it reacts on <Enter> event. How to make the script to react <Enter> event on all widgets when I hold the mouse button?
I apologize for my english.
When a binding fires, the
widgetattribute will always be set to the widget that is handling the event. To find the widget under the mouse you need to use the method winfo_containing.