Reputation: 1
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.
Upvotes: -1
Views: 62
Reputation: 858
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()
Upvotes: 1