CS 115 Lab 4, Part C: Characterize the user's mouse clicks

[Back to lab instructions]


The Big Picture

In this part of the lab, you will modify the program that you wrote for part B so that you can accept the user's mouse-clicks and determine in which row and column each click occurred. If a mouse-click happens to be outside of the grid, your program will report that as well.

Determining the row and the column of a mouse-click

Create a new Python program and call it lab04c.py. Copy and paste your previous program (lab04b.py) into it. Now, add the following loop to the end of your program and just before the last two lines.

    for i in range(10):
        c_point = window.getMouse()
        x_c_point = c_point.getX()
        y_c_point = c_point.getY()
        print('x =', x_c_point, 'y =', y_c_point)

The idea is to, just as in part A of this lab, accept the user's mouse-clicks and determine where they occur. In this part, if the mouse-click occurs in one of the num_rows * num_columns squares, we want to identify its row- and column-number (where the number of the first row and column is 1).

Remember that the top left of the grid begins at (100, 100).

Let's suppose that when you run your program and click the mouse, the x and the y of a mouse-click takes place at (235, 540). That is, x = 235 and y = 540. Here's a procedure you might follow:

Answer Question 7 in your writeup.

Modify your program so that it accepts 10 user clicks and identify the row and the column in which the clock occurred. If the click occurs outside of the grid, your program should indicate so. The output of your program should look like this for a 10x10 grid:

The click at (364, 195) is in row 2, column 5.
The click at (388, 48) is outside of the grid.
The click at (186, 481) is in row 7, column 2.
The click at (60, 472) is outside of the grid.
The click at (431, 366) is in row 5, column 6.
The click at (617, 248) is in row 3, column 9.
The click at (520, 765) is outside of the grid.
The click at (670, 484) is in row 7, column 10.
The click at (253, 430) is in row 6, column 3.
The click at (132, 444) is in row 6, column 1.

Be sure your docstring is up to date with your name and a current description of your program.

Stop here and demo your solution. Then, continue to Part D to submit your program.