import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=500, height=500) canvas.pack() # create vertical lines for x in range(0, 501, 50): canvas.create_line(x, 0, x, 500) # create horizontal lines for y in range(0, 501, 50): canvas.create_line(0, y, 500, y) root.mainloop()
import tkinter as tk root = tk.Tk() canvas = tk.Canvas(root, width=500, height=500) canvas.pack() square_size = 50 # create white and black squares for row in range(8): for col in range(8): if (row + col) % 2 == 0: color = 'white' else: color = 'black' x1 = col * square_size y1 = row * square_size x2 = x1 + square_size y2 = y1 + square_size canvas.create_rectangle(x1, y1, x2, y2, fill=color) root.mainloop()In this example, a chess board grid is created by drawing black and white squares alternatively. Package library: tkinter.