Coloring a square grid by clicking

just select n for a nxn grid

n = 5;
Grid[Partition[
Table[DynamicModule[{col = White}, 
EventHandler[
 Dynamic[Graphics[{EdgeForm[Thick], col, Rectangle[]}, 
   ImageSize -> 
    Tiny]], {"MouseClicked" :> (col = 
     col /. {Black -> White, White -> Black})}]], {n^2}], n]]

here is the result

enter image description here


n = 10;
m = ConstantArray[0, {n, n}];
Row[{Dynamic[EventHandler[ArrayPlot[m, Mesh -> All, ImageSize -> 300], 
  {"MouseClicked" :> With[{p = Reverse[{1, n} + {1, -1} Floor@MousePosition["Graphics"]]},
   m[[## & @@ p]] = m[[## & @@ p]] /. {0 -> 1, 1 -> 0}]}]], 
 Dynamic[Style[MatrixForm[m], 24]]}, Spacer[20]]

enter image description here