I am trying to create binding in a loop using tkinter module.
from tkinter import *
class Gui(Frame):def __init__(self, parent):Frame.__init__(self, parent) self.parent = parentself.initUI()def Arrays(self,rankings):self.panels = {}self.helpLf = LabelFrame(self, text="Array Layout:")self.helpLf.grid(row=10, column=9, columnspan=5, rowspan=8)for rows in range(10):for cols in range(10):x = str(rows)+"_"+str(cols)self.row = Frame(self.helpLf)self.bat = Button(self.helpLf,text=" ", bg = "white")self.bat.grid(row=10+rows, column=cols)self.panels[x] = self.batself.panels[x].bind('<Button-1>', self.make_lambda())self.panels[x].bind('<Double-1>', self.color_change1)def color_change(self, event):"""Changes the button's color"""self.bat.configure(bg = "green")def color_change1(self, event):self.bat.configure(bg = "red")
There are 10X10= 100 buttons here. the binder works only for the last button. Does anyone know how can I apply the binder for all the buttons?