I have to creat a program that draws squares instead of circles. It also has to draw additional squares for each mouse click, and at the end print a message "Click again to quit" after the loop, and wait for a final clikc before closing the window. This is what I have so far, but I think there is something wrong, because instead of drawing circles it stays on the same place. Please help, thank you.

def main():
win = GraphWin()
shape= Rectangle(Point(300,300),Point(250,250))
shape.setOutline("red")
shape. setFill("red")
shape.draw(win)
for i in range(10):
p=win.getMouse()
c=shape.getCenter()
dx=p.getX()-c.getX()
dy=p.getY()-c.getY()
shape.move(dx,dy)
message = Text(Point(0, 0, "Click anywhere to Quit")
message.draw(win)
win.close()
main()

Maybe I am getting old, but I do not see any circles nor any Python indention (with code tags).

Edited 4 Years Ago by mike_2000_17: Fixed formatting

You may want to modify something like that ...

# using the Zelle graphics module (derived from Tkinter)
# http://mcsp.wartburg.edu/zelle/python/graphics.py

from graphics import *

def main():
    w = 350
    h = 250
    win = GraphWin("Click to move shape (10 clicks max)", w, h)    
    #shape = Rectangle(Point(200,200),Point(250,250))
    shape = Circle(Point(100,100), 20)
    shape.setOutline("red")
    shape. setFill("red")
    shape.draw(win)
    for k in range(10):
        message = Text(Point(40, 10), "clicks = %s" % (k+1))
        message.draw(win)
        p = win.getMouse()
        c = shape.getCenter()
        dx = p.getX() - c.getX()
        dy = p.getY() - c.getY()
        shape.move(dx,dy)
        # reset text
        message.setText("")

    win.getMouse()
    win.close()

main()
This question has already been answered. Start a new discussion instead.