Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38209

Re: Detecting a click on the turtle screen when the turtle isn't doing anything?

Newsgroups comp.lang.python
Date 2013-02-05 10:08 -0800
References <5id7u9x7rd.ln2@news.ducksburg.com>
Message-ID <8e3f3198-3657-4abc-b367-06479a561e41@googlegroups.com> (permalink)
Subject Re: Detecting a click on the turtle screen when the turtle isn't doing anything?
From woooee@gmail.com

Show all headers | View raw


> 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()
> 
> ...
> 
> 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)

Note that the code you posted does not call onclick().  Globals are confusing IMHO.  Code becomes cleaner and easier to write and read when you become familiar with classes.

import turtle

class TurtleTest():
    def __init__(self):
        self.ctr=0
  
        t = turtle.Turtle() 
        s = turtle.Screen() 
        s.onclick(self.clicked)
        turtle.mainloop()

    def clicked(self, x, y):
        print self.ctr
        if 0 == self.ctr:
            self.first() 
        elif 1 == self.ctr:
            self.second()      
        elif 2 == self.ctr:
            self.third()

        self.ctr += 1

    def first(self):
        print "first called"

    def second(self):
        print "second called"

    def third(self):
        print "third called"

TT = TurtleTest()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 13:20 +0000
  Re: Detecting a click on the turtle screen when the turtle isn't doing anything? woooee@gmail.com - 2013-02-05 10:08 -0800
    Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 19:58 +0000
      Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Dave Angel <d@davea.name> - 2013-02-05 16:55 -0500
        Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-06 21:46 +0000
  Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-05 19:45 +0000
    Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-05 16:54 -0500
      Re: Detecting a click on the turtle screen when the turtle isn't doing anything? Adam Funk <a24061@ducksburg.com> - 2013-02-06 21:52 +0000

csiph-web