I have a 2d array of tkinter buttons.
It looks like this:
I want to be able to click on a button, hold my mouse down, and every button that is hovered over while my mouse is pressed down changes colors. So far I have it to the point where if you hover over any square regardless if a mouse button is pressed it changes colors.
The code looks like this so far:
def draw(self, i, j):
button = self.buttons[i][j]
button.bind('<Enter>', lambda event: self.on_enter(event, button))
def on_enter(self, e, button):
button['background'] = 'green'
To be clear, I want to be able to change a button's color when left-click is held down and a button is hovered over at the same time.
Thanks for helping me.
EDIT: removed picture of code and provided something that can be copy and pasted.
2ND EDIT: the code is about 100 lines, but the gist is there's a 2d array of tkinter buttons, and the code I provided shows the 2 functions responsible for changing the color of the buttons. If more code is needed, I'll put it in.
question from:
https://stackoverflow.com/questions/65933562/how-do-you-change-the-state-of-multiple-tkinter-buttons-when-your-mouse-is-press 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…