Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNancy Melucci
Courses Plus Student 36,143 Pointsgraphics.py: moving a circle around a window on mouse click
Hoping someone is familiar with Zelle's graphics module. I need to create a program that calls a method 10 times. The method draws a circle on a mouse click. I was able to make the circle appear in a new location (but not the original circle disappear). I've created a method (which I am sure is not correct) and a while loop. What am I missing? The circle should present when the window opens, the user clicks 10 times, each time the circle moves to a new location, and then the program ends with it in its final position. My code below, with description. Thanks.
#moveTo(shape, newCenter) shape is a graphics object that supports the getCenter method and
# newCenter is a Point. Moves shape so that newCenter is its center.
'''Use your function to write a program that draws a circle
and then allows the user to click the window 10 times.
Each time the user clicks, the circle is moved where the user clicked.'''
from graphics import *
def moveTo(newCenter):
win = GraphWin
circle = Point(newCenter.getX(), newCenter.getY())
circle.draw(win)
newCenter.getMouse()
return circle
def main():
win = GraphWin("Move the Circle", 1000, 1000)
c = Circle(Point(500, 300), 100)
c.draw(win)
i = 0
while i <=10:
p = win.getMouse()
moveTo(p)
i = i + 1
main()
Nancy Melucci
Courses Plus Student 36,143 PointsNancy Melucci
Courses Plus Student 36,143 PointsHere is the error that currently is thrown after the window appears:
C:\Users\Nancy\AppData\Local\Programs\Python\Python35-32\python.exe C:/Users/Nancy/PycharmProjects/MiraCosta/circlemover.py Traceback (most recent call last): File "C:/Users/Nancy/PycharmProjects/MiraCosta/circlemover.py", line 26, in <module> main() File "C:/Users/Nancy/PycharmProjects/MiraCosta/circlemover.py", line 20, in main moveTo(p) File "C:/Users/Nancy/PycharmProjects/MiraCosta/circlemover.py", line 7, in moveTo circle.draw(win) File "C:\Users\Nancy\PycharmProjects\MiraCosta\graphics.py", line 479, in draw if graphwin.isClosed(): raise GraphicsError("Can't draw to closed window") TypeError: isClosed() missing 1 required positional argument: 'self'