Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 9 - GUI Programming using Tkinter - Programming Exercises - Page 304: 9.5

Answer

code

Work Step by Step

# 9.5 (Game: display a checkerboard) Write a program that displays a checkerboard in # which each white and black cell is a canvas with a background of black or white, # as shown in Figure 9.25a. from tkinter import * window = Tk() c = Canvas(window, width=320, height=320) c.pack() color = 0 x1 = y1 = 3 x2 = y2 = 43 for i in range(8): for j in range(8): if color == 0: c.create_rectangle(x1, y1, x2, y2, fill="white", outline="white") color = 1 elif color == 1: c.create_rectangle(x1, y1, x2, y2, fill="black") color = 0 x1 = x2 x2 = x1 + 40 y1 = y2 y2 = y1 + 40 x1 = 3 x2 = 43 color = 1 if color == 0 else 0 window.mainloop()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.