# # file: mouse-clicks.py # # from graphics import * def main(): win=GraphWin("Practicing with Mouse Clicks",480,360) win.setBackground('white') str1=Text(Point(240,10),"Please click a mouse somewhere in this window 4 times.") str1.draw(win) str2=Text(Point(240,30),"Each time you'll get the coordinates of the spot.") str2.draw(win) for i in range(4): x=win.getMouse() if(i==0): str2.undraw() # erase str2 from the window after the first click # print "You clicked at (%d,%d)." % (x.getX(),x.getY()) str1.setText("You clicked at (%d,%d)." % (x.getX(),x.getY())) str=Text(Point(240,70),"Click once more to close the window.") str.draw(win) x=win.getMouse() win.close() main()