回答編集履歴
1
追記
answer
CHANGED
@@ -2,5 +2,7 @@
|
|
2
2
|
次のようにデフォルト引数で逃げるのが一つの手段です。
|
3
3
|
```Python
|
4
4
|
for i in range(2):
|
5
|
-
b.append(tk.Button(root, text=str(i), command=lambda i=i:print(i)))
|
5
|
+
b.append(tk.Button(root, text=str(i), command=lambda i=i: print(i)))
|
6
|
-
```
|
6
|
+
```
|
7
|
+
|
8
|
+
**参考**: [ループの中で異なる値で定義されたラムダ式が、同じ値を返すのはなぜですか?](https://docs.python.org/ja/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result)
|