horstjens/ThePythonGameBook — comment on commit 4404b2096fddb11155b750f1e3b6c822213ad58c
File: pygame/gameOfLife.py line 137
By yipyip:

mouse_x, mouse_y = pygame.mouse.get_pos()

screen_x, screen_y = mouse_x - x_offset, mouse_y - y_offset

# use integer division
cell_x, cell_y = screen_x // cell_width, screen_y // cell_height

if 0 <= cell_x < max_x and 0 <= cell_x < max_y:
cells[cell_x, cell_y] = 1