My Python Stuff

Click HERE to return to homepage.

Python Lab 7

Key Handlers

1. When the program is run, there is a black canvas and two boxes for key and mouse inputs.

2. When I comment out line 8, the code returns an error, claiming there is bad input for the parameters (it’s not defined).

3. It enlarges the letter size, the coordinates (where it shows up), and the color of the letter that shows up on the canvas.

4. Yes the code still runs properly. In order for it to work you must also change the code on line 16 to “myCanvas”. 5. It gives an infinite list of numbers because it’s a global variable and the code tells it to take the value and add 1 to it (and repeat).

Mouse Handlers

1. “Ball_pos” stands for the position of the ball.

2. The ball moves to the top left corner of the canvas, where to origin is located.

3. The name of the function is “click”, the input parameter must be the position of the click (latitude and longitude of the mouse click).

4. The ball moves to wherever you click. If line 13 is commented out, the ball does NOT move to wherever you click.

5. You can now drag the ball around the canvas by moving the mouse (the ball sticks with the mouse).

Images and Sounds

1. The spaceship image appears on the canvas and the rocket sound plays, even if you close the program. The only way you can stop it is if you hit the reset button.

2. The size of the image changes...the image appears much smaller than before.

3. The list change switches the image to the second image.

4. The new picture is just a weird portion of the original picture.

5.This value is the orientation in radians.

6.If the down key is pressed the ship moves down.

7. http://www.codeskulptor.org/#user41_wSa90uuDPy_1.py

8. http://www.codeskulptor.org/#user41_wSa90uuDPy_2.py