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

Creating a Piece class

Think about it. We need to define rules for all the different chess pieces. Some attributes and methods, such as color, will be common to all the chess pieces, while other attributes/methods, such as rules for movement, will vary for each chess piece.

First, we'll define a new Piece class. This class will have the attributes and methods that are common to all the chess pieces. Then, we will define classes for every individual piece as a subclass of this parent Piece class. We can then override all the attributes and methods in these individual classes. The code will look like this (see 4.02piece.py):

from configurations import *class Piece():  def __init__(self, color):    self.name = self.__class__.__name__.lower() if ...

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