If you have some X and Y coordinates in the window (let's call them, say, window_x
and window_y
) and you want to get the coordinates on a grid (let's call them grid_x
, andgrid_y
), and each grid cell has a width and height of grid_size
, it is relatively easy to calculate grid_x
and grid_y
: simply integer divide (round down; in Python, that would be the //
operator) window_x
by grid_size
to get grid_x
. You can probably figure out grid_y
.
Can getMouse act on one specific object in Python?
-
16-01-2022 - |
Question
I am trying to make a Tic Tac Toe game in Python using the Zellegraphics module. I want to use getMouse
for mouse input but I am unable to figure out how to make getMouse
to work on one cell of the board. I defined 9 different squares and what I want to do is that if the user clicks on one certain square, I want to draw the X or the O there. I can't figure out how to do that, because as far as I know, getMouse
only acts on the whole window.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow