Recording a move in the data structure

The shift method defined in view.py is responsible for the actual moving of a chess piece on the chessboard. However, this brings about a change in the underlying data structure. The move method of the Model class is then responsible for updating the data structure. This move method is called from the previously defined pre_move_validation() method if and only if no errors are raised, as follows (4.06model.py):

def move(self, start_pos, final_pos): self[final_pos] = self.pop(start_pos, None)

Note that as soon as this update is complete, the control returns to the on_square_clicked() method in view.py. The method then calls the draw_all_pieces() method, which updates the view.

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.