PYTHON Please use Tkinter Write a program that displays an 8
PYTHON! Please use Tkinter:
Write a program that displays an 8 times 8 grid, as shown in Figure 9.25c. Use red for vertical lines and blue for horizontal lines.Solution
from tkinter import *
class SampleGrid:
def __init__(self):
self.window = Tk() ## creating window from Tk() method
self.window.title(\"Grid 8*8\") ## set title
self.canvas = Canvas(self.window, width=128, ## set width and hight for window and background
height=128, bg = \"white\")
self.display_lines(16, 0, 16, 128, \"red\") ## call function display_lines() with required parameters
self.display_lines(0, 16, 128, 16, \"blue\")
self.canvas.pack()
self.window.mainloop()
def display_lines(self, x1, y1, x2, y2, color): ## display_lines() definition
x_plus = x1 ## all lines are evenly spaced
y_plus = y1
for ctr in range(7):
self.canvas.create_line(x1, y1, x2, y2, fill = color) ## creating line
x1 += x_plus ## incrementing for evenly spaced columns and rows.
x2 += x_plus
y1 += y_plus
y2 += y_plus
CG = SampleGrid()
