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

Dave Angel d at
Tue Feb 5 22:55:55 CET 2013

On 02/05/2013 02:58 PM, Adam Funk wrote:
> On 2013-02-05, woooee at wrote:
>>    <SNIP>
>> Globals are
>>   confusing IMHO.  Code becomes cleaner and easier to write and read
>>   when you become familiar with classes.
>   If I have to write a class just to create
> one instance of it & call the main() method, I might as well use Java!
> ;-)

I'm no fan of Java.  But it's not about a "main" method, it's about 
sharing data between functions.  Most of the time non-constant globals 
are a mistake.  If the data can't be passed as an argument, then it 
should probably be part of the instance data of some class.  Which class 
is a design decision, and unlike Java, I wouldn't encourage writing a 
class for unrelated functions, just to bundle them together.

Anyway, back to your problem.  Since your code doesn't have threads, it 
must have an event loop somewhere.  Event loops don't coexist at all 
well with calls to sleep().

     while waiting:

If you start that code with waiting being true, it will never terminate.

I don't know turtle graphics, but if it's got an event loop, then you 
can't write your program procedurally.  A function called 
"wait_for_click()" is nonsensical.


More information about the Python-list mailing list