March 2018
Beginner to intermediate
422 pages
10h 33m
English
Now, let's turn our attention to displaying all the chess pieces on the chessboard.
First, we'll define a method named draw_single_piece, which draws a chess piece at the given position when it's given a position, and the character representing the chess piece as follows (see 4.03—view.py):
def draw_single_piece(self, position, piece): x, y = self.controller.get_numeric_notation(position) if piece: filename = "../pieces_image/{}_{}.png".format(piece.name.lower(), piece.color) if filename not in self.images: self.images[filename] = PhotoImage(file=filename) x0, y0 = self.calculate_piece_coordinate(x, y) self.canvas.create_image(x0, y0, image=self.images[filename], tags=("occupied"), anchor="c")
Read now
Unlock full access