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

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.

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