How do I Create a Checkers board using the graphics module?

49 Views Asked by At

Im trying to make a chessboard(checkers) usuing graphics module strictly. No Arrays etc.


from graphics import*

> > #Graphics WindoW
def graphics_window():
win = GraphWin('Checkers', 600, 600)
win.setBackground("white")
win.getMouse()
win.close()

> > #Make Checkers Board
def Checkersboard():`

Now I am strugling to started with the red & black board.

1

There are 1 best solutions below

1
On

Try using nested loops and draw a square of alternating colors (x64). Your board was defined as 600x600, so I set the squares to 75x75 (600/8).

from graphics import *

def Checkersboard():
    win = GraphWin("Checkers", 600, 600)
    win.setBackground("white")

    for i in range(8):
        for j in range(8):
            if (i + j) % 2 == 0:
                color = "red"
            else:
                color = "black"

            square = Rectangle(Point(i * 75, j * 75), Point((i + 1) * 75, (j + 1) * 75))
            square.setFill(color)
            square.draw(win)

    win.getMouse()
    win.close()

Checkersboard()

Red and Black Checker Board in Python