[Tutor] Questions about the new turtle module in Python 2.6b2

Dick Moores rdm at rcblue.com
Sun Aug 10 16:28:33 CEST 2008


At 11:57 PM 8/9/2008, you wrote:
>Dick Moores schrieb:
>>Gregor,
>>
>><http://docs.python.org/dev/library/turtle.html#turtle.setup>
>>1. I want the window to open with the right edge 0 pixels from the 
>>right edge of my screen.
>>However, setup(width=.75, height=.915, startx=-0, starty=0) doesn't 
>>work. I have to do the nearest thing,
>>setup(width=.75, height=.915, startx=-1, starty=0). A small thing, 
>>but what's wrong with perfection.
>Hi Dick,
>a good observation, but I think this cannot be changed, because  of
>
> >>> -0 == 0
>True

OK. I just thought there might be a workaround. Or should be.

>in Python
>>2. There's a lot I don't understand in
>>turtle.setup(width=_CFG[, "width"], height=_CFG[, "height"], 
>>startx=_CFG[, "leftright"], starty=_CFG[, "topbottom"])
>>
>>What is '_CFG'? And how should anyone know what it is?
>>What is "leftright"? And how to use it?
>>What is "topbottom"? And how to use it?
>_CFG is an internal dictionary, which contains configuration data. 
>You can change these
>by editing adding or editing the turtle.cfg file (an example is in 
>the Demo directory).
>How to do this you can find here:
>
>http://docs.python.org/dev/library/turtle.html#how-to-configure-screen-and-turtles 
>

I suppose you'll add a mention of '_CFG' to that?

>>3. http://docs.python.org/dev/library/turtle.html#turtle.stamp
>>
>>"turtle.stamp()
>>Stamp a copy of the turtle shape onto the canvas at the current 
>>turtle position. Return a stamp_id for that stamp, which can be 
>>used to delete it by calling clearstamp(stamp_id)."
>>
>>But in your version 1 
>>(<http://article.gmane.org/gmane.comp.python.tutor/49805>), the 
>>turtle is hidden by hideturtle()! What are you stamping? It seems 
>>the shape, or rectangle. If so, why does the doc say 'turtle'?
>there will be stamped the shape of the turtle, that appeared  if it 
>were not hidden.

But what get's 'stamped' is not only the turtle, is it. That's what 
is confusing, IMO. And would it not be a good idea to define 'stamp'?

>General remark: you can investigate Python and especially its turtle 
>module interactively
>using IDLE. But note: in the case of graphics (Tkinter and 
>especially turtle.py) you have to
>use the -n switch of IDLE. So the link calling idle must look 
>something like this:
>
>/... ../... ../python  /... ../.../.../idle.pyw -n
>
>the dotted parts representig the path according to your system configuration
>
>If you have done this onceyou can issue function calls on after another and
>observe what happens. E. g.:
>
> >>> from turtle import *
> >>> reset()
> >>> shape("square")
> >>> color("blue", "red")
> >>> resizemode("user")   #  at first no visual effect, but ...
> >>> turtlesize(2,3,5)
> >>> fd(100)
> >>> left(45)
> >>> pensize(8)
> >>> fd(100)
> >>> left(90)
> >>> pencolor("green")
> >>> fd(100)
> >>> turtlesize(1,5)
> >>> left(1080)
> >>> stamp()
>8
> >>> left(45)
> >>> ht()
> >>> fd(100)
> >>> stamp()
>9
> >>> left(45)
> >>> fd(100)
> >>> stamp()
>10
> >>>
>
>... and so on.
>If you want to know how some function works and the docs
>don't give you a proper clue, simply try out.

Ah. Very good. After doing that I understand a lot more now. However, 
it was of no help with "leftright" or "topbottom" of my question #2.

>>4. For my random_rectangles.py program I've started to try out the 
>>new turtle. (See the current state of random_rectanglesV16_web.py 
>>at <http://py77.python.pastebin.com/d3e842821>.)  The only downside 
>>I've found is that the new turtle is much faster that the old. I 
>>want to set the speed so that the outlines of rectangles are drawn 
>>slowly enough that the user (me at present) can both appreciate the 
>>colors and have time to check the names of the colors being printed 
>>in the console window. Using the old turtle, I found that a default 
>>delay of 1 ((delay(1)) was just right; with the new turtle, setting 
>>a delay of even 50 affects only the first cycle of rectangles. So I 
>>don't use delay at all. Setting the slowest speed of 1 (speed(1)) 
>>is still too fast. How can I slow down the drawing of the rectangles?
>I suppose you have some call of reset() or clear() which resets the 
>delay. So try a
>delay call at the beginning of every cycle.

You're right! The clear() between cycles was doing that. So now I 
have speed(spd) at the top of draw_rect(). And now I find that 
speed(4) and delay(15) work the best for what I want. So those are 
now the defaults. BTW the latest version is 
<http://py77.python.pastebin.com/pastebin.php?diff=f159f133d>. Now 
the user can accept all the defaults at once. (See the prompt for 
this, line 427. Also, the dimensions of the window and of the 
rectangles are now proportional to the size and resolution of the 
user's monitor. See new function 
adjust_for_monitor_size_and_resolution(), line 196, and revised 
function get_next_rect_params(), lines 207-209.

>>5. I've been unable to figure out how to use onclick() 
>>(<http://docs.python.org/dev/library/turtle.html#turtle.onclick>). 
>>I'd like to find a way to pause my script by clicking on the screen 
>>-- so I could snag an image of what's showing, and then click again 
>>to restart the drawing of the rectangles. And in addition, being 
>>able to stop the program with a double click on the screen would be 
>>very handy. Could you explain how to do these, if in fact they are possible?
>This idea for an event driven program affords a bit of different 
>thinking and a different
>program structure. I'll come up with a proposition and an explanation of some
>prerequisites  in  another posting. (I have not got the time  to do 
>that  now).

Great! Thank you.

Dick




More information about the Tutor mailing list