The code above draws a basic grid. I would like to do the following things.
- Know where the user clicks on the draw so as to change the face color of a rectangle. The problem is to know that the user has clicked and then to have the coordinates of the click. Is it possible ?
- I would like also to interact with key events. For example, if the space key is activated, I would like to go back to the initial draw. The problem is to know that a key has been pressed, and to have the ascii code of this key. Is it possible ?
MY STARTING CODE
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
n = 2**3
plt.axes(xlim = (0, n), ylim = (0, n))
plt.axis('off')
for line in range(n):
for col in range(n):
rect = mpatches.Rectangle(
(line, col), 1, 1,
facecolor = "white",
edgecolor = "black"
)
plt.gca().add_patch(rect)
plt.show()