WIDTH = HEIGHT = 800
DIMENSION = 8
SQ_SIZE = HEIGHT / DIMENSION
IMAGES = {}
def draw_board():
colors = ["white", "black"]
for r in range(DIMENSION+1):
for c in range(DIMENSION+1):
canvas.create_rectangle(100, 100, r * (WIDTH / DIMENSION), c * (WIDTH / DIMENSION), fill=colors[((r+c)%2)])
def load_images():
pass
if __name__ == "__main__":
root = Tk()
root.resizable(False, False)
canvas = Canvas(root, width=WIDTH, height=HEIGHT)
draw_board()
canvas.pack()
root.mainloop()
the goal is draw a checkerboard for chess. if I do it without the fill argument it works as expected but when I add the fill option its either all black, or white(depending on how I arrange the colors in the colors array.)
how can I solve this without hardcoding every single square?
PS: I tested the colors[((r+c)%2)] by printing it and it works as expected