I'm trying to bind a function to all the buttons in my App and pass Extra Parameters as well
However, all the buttons getting the same parameters instead of a unique parameter for each one(the parameters of the last button in the for loop)
Any suggestions on what am I doing wrong?
def add_buttons(self, letters):
for i, row in enumerate(letters):
for j, letter in enumerate(row):
btn = Button(self._bottom_mid, text=letter, font=self._myFont, bg=WHITE_COLOR,
fg=BLUE_COLOR, padx=30, pady=30)
btn.place(relx=i * 0.2 + 0.1, rely=j * 0.2 + 0.1, relwidth=0.2, relheight=0.2)
btn.bind("<Button-1>", lambda e: self._boggle.moused_clicked(e, (i, j), letter))
def moused_clicked(e, coordinate, letter):
print(coordinate)
print(letter)
# The output is always the coordinate of
# the last button no matter what button was clicked on