So I'm creating the game of life in python, and would like to create a grid on top of a canvas using the tkinter class of python. Thanks in advance.
To make the grid I'm using the create_line() function of the canvas class and looping through using the range() function so that my lines are drawn to the width and the height of the canvas, using two separate for loops one for width and one for the height. The loops I have gotten are taken from the following piece of code on stackoverflow: How to create a grid on tkinter in python? I thought I understood what is happening but what I thought should happen has not
from tkinter import *
from random import *
window = Tk()
window.title('Game Of Life')
canvas = Canvas(window, background='white', width=800, height=600)
def create_grid(canvas):
width = canvas.winfo_width() # gets width of the canvas
height = canvas.winfo_height() # gets height of the canvas
for line in range(0, width, 1): # range(start, stop, step)
canvas.create_line([(line, 0), (line, height)], fill='black', tags='grid_line_w')
for line in range(0, height, 1):
canvas.create_line([(0, line), (width, line)], fill='black', tags='grid_line_h')
create_grid(canvas)
canvas.grid(row=0, column=0)
window.mainloop()
My expected results are to have a white canvas with vertical and horizontal lines stretching the width and height of the canvas. But my actual results are just a white canvas with no lines on top.