I want to generate n
amount of Tkinter Button
s which do different things. I have this code:
import Tkinter as tk
for i in range(boardWidth):
newButton = tk.Button(root, text=str(i+1),
command=lambda: Board.playColumn(i+1, Board.getCurrentPlayer()))
Board.boardButtons.append(newButton)
If boardWidth
is 5, though I get buttons labelled 1
to 5
, when clicked they all do Board.playColumn(5, Board.getCurrentPlayer())
.
I need the first button to do Board.playColumn(1, Board.getCurrentPlayer())
, the second to do Board.playColumn(2, Board.getCurrentPlayer())
and so on.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…