On 2013-02-05, Adam Funk wrote: > I'm trying to get a program to do some plotting with turtle graphics, > then wait for the user to click on the graphics window, then do some > more plotting, &c. So far I have the following, which doesn't work: > > #v+ > waiting = False > > def clicked(x, y): > global waiting > print('clicked at %f %f' % (x,y)) > waiting = False > return > > def wait_for_click(s): > global waiting > waiting = True > s.listen() > while waiting: > time.sleep(1) > return > > > ... > t = turtle.Pen() > s = turtle.Screen()
Oops, I snipped out two important lines: #v+ s.onclick(clicked, btn=1) wait_for_click(s, t) #v- > ... > traverse.plot(s, t, "black", scale, adjx, adjy) > wait_for_click(s) > bowditch.plot(s, t, "red", scale, adjx, adjy) > wait_for_click(s) > transit.plot(s, t, "blue", scale, adjx, adjy) > wait_for_click(s) > #v- > > > Each of my plot(..) calls does some turtle movement, and I want the > program to sit and wait for the user to click the graphics window, > then add the next plot. I've played around with some event handling > examples I found [1], and concluded that the onclick binding only > works while the turtle is doing something. Is that correct? Is there > a way to wait for the click & hear it while the turtle is not doing > anything? > > > [1] > <http://csil-web.cs.surrey.sfu.ca/cmpt120fall2010/wiki/IntroToEventHandling/> > > > Thanks, > Adam > > -- Master Foo said: "A man who mistakes secrets for knowledge is like a man who, seeking light, hugs a candle so closely that he smothers it and burns his hand." --- Eric Raymond -- http://mail.python.org/mailman/listinfo/python-list