[Tutor] full screen turtle.py
reavey
reavey@nep.net
Mon Mar 17 18:26:33 2003
Re: [Tutor] full screen turtle.py add this thread to my home page
by Gregor Lingl other posts by this author
Feb 11 2003 10:38PM messages near this date
<< Re: [Tutor] Sun says: Don't use Java, use Python! | RE:
[Tutor] List exercise >>
reavey schrieb:
> is there a way to display a full screen when turtle.py initializes?
As a default-canvas is created the first time when you call an arbitrary
turtle-graphics
function, there is no way to pass information about its size to the canvas.
But:
(1) There is the possibility to create turtle-objects on your own
Tkinter-Canvas
which may have any size you want. more precisely, you have to create
an object of the RawPen class, which goes like this:
>>> from Tkinter import Canvas
>>> cv = Canvas(width=800, height=600)
>>> cv.pack()
>>> t = RawPen(cv)
>>> t.forward(100)
you may reset the size of cv with something like:
>>> cv["width"]=400
>>> cv["height"] = 500
and recenter t by calling t.reset (which works essentially the same way
you used when resizing the default-canvas manually)
(2) Another way to accomplish what you want ist do decide to rewrite
the reset-function of the turtle-module in order to pass information
about the size of the canvas. (If these arguments are not given, it
works the old way):
First you have to change the reset-method of RawPen (approx line 40):
def reset(self, width = None, height = None):
canvas = self._canvas
if width: canvas["width"] = width
if height: canvas["height"] = height
self._canvas.update()
# .... and so on. as before
Then you have to modify the reset - function (approx line 350):
def reset(width=None, height=None): _getpen().reset(width,height)
I've attached a modified turtle.py
With these changes the following will be possible:
>>> from turtle import *
>>> reset(800,600)
>>> forward(50)
>>> reset(200,200)
Regards, Gregor
P.S. I didn't extensively test these changes, so maybe there will be
some unwanted side-effects, especially when using RawPen.
Maybe I'll have a look at this sometimes later ...
>
> The first canvas takes up a small portion of the display (around 10%).
> When I hit the expand button on the canvas it doesn't recenter.
> The drawing still uses the inititial canvas coordinates.
>
> btw: this is not a problem using the interactive interpreter as a
> turtle.reset()
> issued after you expand works as expected.
>
> thanks
> re-v
I have tried part two being the better solution.
I get the following error
traceback(most recent call last)
file "<stdin>",line 1 in?
############## the reader of this message will please from this point on
replace the word file with File
"usr/lib/python2.2/lib-tk/turtle.py#################
file line 314, in reset
def reset(width=None,height=None)::_getpen().reset(height,width)
file line 308 in_getpen_pen=pen=Pen()
file line 292, in__init__RawPen.__init__(self._canvas)
file line 16, in__init__self.reset()
file line 34 , in reset self._origin = float(width)/2.0,float(height)/2.0
type error: float() needs a strong argument
from turtle import * ####works
reset() ###produces the above failure
reset(200,200) ####error as above
reset("200","200") ###error as above
Thanks
re-v