我正在尝试将一个函数绑定到我的应用程序中的所有按钮并传递额外参数
但是,所有按钮都获得相同的参数,而不是每个按钮的唯一参数(for循环中最后一个按钮的参数)
关于我做错了什么的任何建议?
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