Answer the question
In order to leave comments, you need to log in
How to draw multiple images in Python using tkinter?
The essence of the project is chess. The first stage, that is, the drawing of the board, was successful:
Next, you need to draw the figures, 80x80 pictures of which I threw into the root folder.
The pieces must be drawn based on the cells of the pieces matrix , which at the beginning of the game
for i in range(8):
for j in range(8):
x = 50 + i * 80 # 50 - отступ, 80х80 - размер клетки
y = 50 + j * 80
if pieces[i][j] == 'wP':
img = PhotoImage(file="WhitePawn.png")
elif pieces[i][j] == 'wK':
img = PhotoImage(file="WhiteKing.png")
elif pieces[i][j] == 'wQ':
img = PhotoImage(file="WhiteQueen.png")
elif pieces[i][j] == 'wR':
img = PhotoImage(file="WhiteRook.png")
elif pieces[i][j] == 'wN':
img = PhotoImage(file="WhiteKnight.png")
elif pieces[i][j] == 'wB':
img = PhotoImage(file="WhiteBishop.png")
elif pieces[i][j] == 'bP':
img = PhotoImage(file="BlackPawn.png")
elif pieces[i][j] == 'bK':
img = PhotoImage(file="BlackKing.png")
elif pieces[i][j] == 'bQ':
img = PhotoImage(file="BlackQueen.png")
elif pieces[i][j] == 'bR':
img = PhotoImage(file="BlackRook.png")
elif pieces[i][j] == 'bN':
img = PhotoImage(file="BlackKnight.png")
elif pieces[i][j] == 'bB':
img = PhotoImage(file="BlackBishop.png")
canvas.create_image(x,y, anchor=NW, image=img)
print(x, ' ', y, ' ', img) #отладка
img = ''
Answer the question
In order to leave comments, you need to log in
all because you have one img variable and you need an array equal to the number of cells - 8*8.
or pass the file name and not the image object.
The problem is that the variable limits the number of possible objects to 1, since a reference to the object is passed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question