Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Setup your Python program file \'lab6A.py\' Open a new, blank Python program win

ID: 3856707 • Letter: S

Question

Setup your Python program file 'lab6A.py' Open a new, blank Python program window. At the top of the file, (and without indenting), enter the following command and comments from graphics import * # lab6A.py # {insert your name here} # This program animates a blue square in a 500 times 500 graphics window # It will terminate if a click is detected in the window # Full documentation of the Graphics module can be found at: # http: //mcsp.wartburg.edu/ze11e/python/graphics/graphics.pdf # Create a Graphics window and blue square Write a Python function that creates a 500 times 500 graphics window, then creates and draws a 30 times 30 blue square in the center of the graphics window. Animate the blue square until mouse click Within your function, use a While loop to move the blue square vertically in the Graphics window in increments of 5 pixels until it reaches the edge (either top or bottom), then reverse its direction of movement. The end condition for the While loop is if a mouse click is detected in the Graphics window - use the checkMouse () function. Close the Graphics Window It is important that you close the graphics window at the end of your program. Leaving them open clutters up your display and can cause your computer to hang or perform slowly. Add the following command to your function to close the window. win.close() # close win graphics window

Explanation / Answer

from graphics import *
from math import sqrt

def isClicked(square, mousePos):
distance = sqrt(((point.x - square.x) ** 2) +
((point.y - square.y) ** 2))
return distance < square.side

def main():
win = GraphWin('Example Window', 500, 500)
square = Rectangle(Point(150,150), Point(350,350))
square.setFill('blue')
square.draw(win)
mousePos = win.getMouse()
if isClicked(square, mousePos):
print "You clicked in the square!"
else:
print "You clicked outside the square!"

main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote