O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying chess pieces on the chessboard

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.03view.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")

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required