Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
turtle.TurtleScreen Class Reference
Inheritance diagram for turtle.TurtleScreen:
Inheritance graph
[legend]
Collaboration diagram for turtle.TurtleScreen:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def clear
def mode
def setworldcoordinates
def register_shape
def colormode
def reset
def turtles
def bgcolor
def tracer
def delay
def update
def window_width
def window_height
def getcanvas
def getshapes
def onclick
def onkey
def onkeypress
def listen
def ontimer
def bgpic
def screensize

Public Attributes

 xscale
 yscale
 cv
 canvwidth
 canvheight
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Static Public Attributes

 onscreenclick = onclick
 resetscreen = reset
 clearscreen = clear
 addshape = register_shape
 onkeyrelease = onkey

Private Member Functions

def _colorstr
def _color
def _incrementudc

Private Attributes

 _shapes
 _bgpics
 _mode
 _delayvalue
 _colormode
 _keys
 _bgpic
 _bgpicname
 _tracing
 _updatecounter
 _turtles

Static Private Attributes

 _RUNNING = True

Detailed Description

Provides screen oriented methods like setbg etc.

Only relies upon the methods of TurtleScreenBase and NOT
upon components of the underlying graphics toolkit -
which is Tkinter in this case.

Definition at line 956 of file turtle.py.


Constructor & Destructor Documentation

def turtle.TurtleScreen.__init__ (   self,
  cv,
  mode = _CFG["mode"],
  colormode = _CFG["colormode"],
  delay = _CFG["delay"] 
)

Definition at line 966 of file turtle.py.

00966 
00967                  colormode=_CFG["colormode"], delay=_CFG["delay"]):
00968         self._shapes = {
00969                    "arrow" : Shape("polygon", ((-10,0), (10,0), (0,10))),
00970                   "turtle" : Shape("polygon", ((0,16), (-2,14), (-1,10), (-4,7),
00971                               (-7,9), (-9,8), (-6,5), (-7,1), (-5,-3), (-8,-6),
00972                               (-6,-8), (-4,-5), (0,-7), (4,-5), (6,-8), (8,-6),
00973                               (5,-3), (7,1), (6,5), (9,8), (7,9), (4,7), (1,10),
00974                               (2,14))),
00975                   "circle" : Shape("polygon", ((10,0), (9.51,3.09), (8.09,5.88),
00976                               (5.88,8.09), (3.09,9.51), (0,10), (-3.09,9.51),
00977                               (-5.88,8.09), (-8.09,5.88), (-9.51,3.09), (-10,0),
00978                               (-9.51,-3.09), (-8.09,-5.88), (-5.88,-8.09),
00979                               (-3.09,-9.51), (-0.00,-10.00), (3.09,-9.51),
00980                               (5.88,-8.09), (8.09,-5.88), (9.51,-3.09))),
00981                   "square" : Shape("polygon", ((10,-10), (10,10), (-10,10),
00982                               (-10,-10))),
00983                 "triangle" : Shape("polygon", ((10,-5.77), (0,11.55),
00984                               (-10,-5.77))),
00985                   "classic": Shape("polygon", ((0,0),(-5,-9),(0,-7),(5,-9))),
00986                    "blank" : Shape("image", self._blankimage())
00987                   }
00988 
00989         self._bgpics = {"nopic" : ""}
00990 
00991         TurtleScreenBase.__init__(self, cv)
00992         self._mode = mode
00993         self._delayvalue = delay
00994         self._colormode = _CFG["colormode"]
00995         self._keys = []
00996         self.clear()

Here is the caller graph for this function:


Member Function Documentation

def turtle.TurtleScreen._color (   self,
  cstr 
) [private]

Definition at line 1162 of file turtle.py.

01162 
01163     def _color(self, cstr):
01164         if not cstr.startswith("#"):
01165             return cstr
01166         if len(cstr) == 7:
01167             cl = [int(cstr[i:i+2], 16) for i in (1, 3, 5)]
01168         elif len(cstr) == 4:
01169             cl = [16*int(cstr[h], 16) for h in cstr[1:]]
01170         else:
01171             raise TurtleGraphicsError("bad colorstring: %s" % cstr)
01172         return tuple([c * self._colormode/255 for c in cl])

Here is the caller graph for this function:

def turtle.TurtleScreen._colorstr (   self,
  color 
) [private]
Return color string corresponding to args.

Argument may be a string or a tuple of three
numbers corresponding to actual colormode,
i.e. in the range 0<=n<=colormode.

If the argument doesn't represent a color,
an error is raised.

Definition at line 1135 of file turtle.py.

01135 
01136     def _colorstr(self, color):
01137         """Return color string corresponding to args.
01138 
01139         Argument may be a string or a tuple of three
01140         numbers corresponding to actual colormode,
01141         i.e. in the range 0<=n<=colormode.
01142 
01143         If the argument doesn't represent a color,
01144         an error is raised.
01145         """
01146         if len(color) == 1:
01147             color = color[0]
01148         if isinstance(color, str):
01149             if self._iscolorstring(color) or color == "":
01150                 return color
01151             else:
01152                 raise TurtleGraphicsError("bad color string: %s" % str(color))
01153         try:
01154             r, g, b = color
01155         except:
01156             raise TurtleGraphicsError("bad color arguments: %s" % str(color))
01157         if self._colormode == 1.0:
01158             r, g, b = [round(255.0*x) for x in (r, g, b)]
01159         if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)):
01160             raise TurtleGraphicsError("bad color sequence: %s" % str(color))
01161         return "#%02x%02x%02x" % (r, g, b)

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.TurtleScreen._incrementudc (   self) [private]

Definition at line 1281 of file turtle.py.

01281 
01282     def _incrementudc(self):
01283         "Increment upadate counter."""
01284         if not TurtleScreen._RUNNING:
01285             TurtleScreen._RUNNNING = True
01286             raise Terminator
01287         if self._tracing > 0:
01288             self._updatecounter += 1
01289             self._updatecounter %= self._tracing

def turtle.TurtleScreen.bgcolor (   self,
  args 
)
Set or return backgroundcolor of the TurtleScreen.

Arguments (if given): a color string or three numbers
in the range 0..colormode or a 3-tuple of such numbers.

Example (for a TurtleScreen instance named screen):
>>> screen.bgcolor("orange")
>>> screen.bgcolor()
'orange'
>>> screen.bgcolor(0.5,0,0.5)
>>> screen.bgcolor()
'#800080'

Definition at line 1215 of file turtle.py.

01215 
01216     def bgcolor(self, *args):
01217         """Set or return backgroundcolor of the TurtleScreen.
01218 
01219         Arguments (if given): a color string or three numbers
01220         in the range 0..colormode or a 3-tuple of such numbers.
01221 
01222         Example (for a TurtleScreen instance named screen):
01223         >>> screen.bgcolor("orange")
01224         >>> screen.bgcolor()
01225         'orange'
01226         >>> screen.bgcolor(0.5,0,0.5)
01227         >>> screen.bgcolor()
01228         '#800080'
01229         """
01230         if args:
01231             color = self._colorstr(args)
01232         else:
01233             color = None
01234         color = self._bgcolor(color)
01235         if color is not None:
01236             color = self._color(color)
01237         return color

Here is the call graph for this function:

def turtle.TurtleScreen.bgpic (   self,
  picname = None 
)
Set background image or return name of current backgroundimage.

Optional argument:
picname -- a string, name of a gif-file or "nopic".

If picname is a filename, set the corresponding image as background.
If picname is "nopic", delete backgroundimage, if present.
If picname is None, return the filename of the current backgroundimage.

Example (for a TurtleScreen instance named screen):
>>> screen.bgpic()
'nopic'
>>> screen.bgpic("landscape.gif")
>>> screen.bgpic()
'landscape.gif'

Definition at line 1461 of file turtle.py.

01461 
01462     def bgpic(self, picname=None):
01463         """Set background image or return name of current backgroundimage.
01464 
01465         Optional argument:
01466         picname -- a string, name of a gif-file or "nopic".
01467 
01468         If picname is a filename, set the corresponding image as background.
01469         If picname is "nopic", delete backgroundimage, if present.
01470         If picname is None, return the filename of the current backgroundimage.
01471 
01472         Example (for a TurtleScreen instance named screen):
01473         >>> screen.bgpic()
01474         'nopic'
01475         >>> screen.bgpic("landscape.gif")
01476         >>> screen.bgpic()
01477         'landscape.gif'
01478         """
01479         if picname is None:
01480             return self._bgpicname
01481         if picname not in self._bgpics:
01482             self._bgpics[picname] = self._image(picname)
01483         self._setbgpic(self._bgpic, self._bgpics[picname])
01484         self._bgpicname = picname

Here is the call graph for this function:

def turtle.TurtleScreen.clear (   self)
Delete all drawings and all turtles from the TurtleScreen.

No argument.

Reset empty TurtleScreen to its initial state: white background,
no backgroundimage, no eventbindings and tracing on.

Example (for a TurtleScreen instance named screen):
screen.clear()

Note: this method is not available as function.

Definition at line 997 of file turtle.py.

00997 
00998     def clear(self):
00999         """Delete all drawings and all turtles from the TurtleScreen.
01000 
01001         No argument.
01002 
01003         Reset empty TurtleScreen to its initial state: white background,
01004         no backgroundimage, no eventbindings and tracing on.
01005 
01006         Example (for a TurtleScreen instance named screen):
01007         screen.clear()
01008 
01009         Note: this method is not available as function.
01010         """
01011         self._delayvalue = _CFG["delay"]
01012         self._colormode = _CFG["colormode"]
01013         self._delete("all")
01014         self._bgpic = self._createimage("")
01015         self._bgpicname = "nopic"
01016         self._tracing = 1
01017         self._updatecounter = 0
01018         self._turtles = []
01019         self.bgcolor("white")
01020         for btn in 1, 2, 3:
01021             self.onclick(None, btn)
01022         self.onkeypress(None)
01023         for key in self._keys[:]:
01024             self.onkey(None, key)
01025             self.onkeypress(None, key)
01026         Turtle._pen = None

Here is the call graph for this function:

def turtle.TurtleScreen.colormode (   self,
  cmode = None 
)
Return the colormode or set it to 1.0 or 255.

Optional argument:
cmode -- one of the values 1.0 or 255

r, g, b values of colortriples have to be in range 0..cmode.

Example (for a TurtleScreen instance named screen):
>>> screen.colormode()
1.0
>>> screen.colormode(255)
>>> turtle.pencolor(240,160,80)

Definition at line 1173 of file turtle.py.

01173 
01174     def colormode(self, cmode=None):
01175         """Return the colormode or set it to 1.0 or 255.
01176 
01177         Optional argument:
01178         cmode -- one of the values 1.0 or 255
01179 
01180         r, g, b values of colortriples have to be in range 0..cmode.
01181 
01182         Example (for a TurtleScreen instance named screen):
01183         >>> screen.colormode()
01184         1.0
01185         >>> screen.colormode(255)
01186         >>> turtle.pencolor(240,160,80)
01187         """
01188         if cmode is None:
01189             return self._colormode
01190         if cmode == 1.0:
01191             self._colormode = float(cmode)
01192         elif cmode == 255:
01193             self._colormode = int(cmode)

def turtle.TurtleScreen.delay (   self,
  delay = None 
)
Return or set the drawing delay in milliseconds.

Optional argument:
delay -- positive integer

Example (for a TurtleScreen instance named screen):
>>> screen.delay(15)
>>> screen.delay()
15

Definition at line 1266 of file turtle.py.

01266 
01267     def delay(self, delay=None):
01268         """ Return or set the drawing delay in milliseconds.
01269 
01270         Optional argument:
01271         delay -- positive integer
01272 
01273         Example (for a TurtleScreen instance named screen):
01274         >>> screen.delay(15)
01275         >>> screen.delay()
01276         15
01277         """
01278         if delay is None:
01279             return self._delayvalue
01280         self._delayvalue = int(delay)

Return the Canvas of this TurtleScreen.

No argument.

Example (for a Screen instance named screen):
>>> cv = screen.getcanvas()
>>> cv
<turtle.ScrolledCanvas instance at 0x010742D8>

Definition at line 1319 of file turtle.py.

01319 
01320     def getcanvas(self):
01321         """Return the Canvas of this TurtleScreen.
01322 
01323         No argument.
01324 
01325         Example (for a Screen instance named screen):
01326         >>> cv = screen.getcanvas()
01327         >>> cv
01328         <turtle.ScrolledCanvas instance at 0x010742D8>
01329         """
01330         return self.cv

Return a list of names of all currently available turtle shapes.

No argument.

Example (for a TurtleScreen instance named screen):
>>> screen.getshapes()
['arrow', 'blank', 'circle', ... , 'turtle']

Definition at line 1331 of file turtle.py.

01331 
01332     def getshapes(self):
01333         """Return a list of names of all currently available turtle shapes.
01334 
01335         No argument.
01336 
01337         Example (for a TurtleScreen instance named screen):
01338         >>> screen.getshapes()
01339         ['arrow', 'blank', 'circle', ... , 'turtle']
01340         """
01341         return sorted(self._shapes.keys())

Here is the call graph for this function:

def turtle.TurtleScreen.listen (   self,
  xdummy = None,
  ydummy = None 
)
Set focus on TurtleScreen (in order to collect key-events)

No arguments.
Dummy arguments are provided in order
to be able to pass listen to the onclick method.

Example (for a TurtleScreen instance named screen):
>>> screen.listen()

Definition at line 1428 of file turtle.py.

01428 
01429     def listen(self, xdummy=None, ydummy=None):
01430         """Set focus on TurtleScreen (in order to collect key-events)
01431 
01432         No arguments.
01433         Dummy arguments are provided in order
01434         to be able to pass listen to the onclick method.
01435 
01436         Example (for a TurtleScreen instance named screen):
01437         >>> screen.listen()
01438         """
01439         self._listen()

Here is the caller graph for this function:

def turtle.TurtleScreen.mode (   self,
  mode = None 
)
Set turtle-mode ('standard', 'logo' or 'world') and perform reset.

Optional argument:
mode -- on of the strings 'standard', 'logo' or 'world'

Mode 'standard' is compatible with turtle.py.
Mode 'logo' is compatible with most Logo-Turtle-Graphics.
Mode 'world' uses userdefined 'worldcoordinates'. *Attention*: in
this mode angles appear distorted if x/y unit-ratio doesn't equal 1.
If mode is not given, return the current mode.

     Mode      Initial turtle heading     positive angles
 ------------|-------------------------|-------------------
  'standard'    to the right (east)       counterclockwise
    'logo'        upward    (north)         clockwise

Examples:
>>> mode('logo')   # resets turtle heading to north
>>> mode()
'logo'

Definition at line 1027 of file turtle.py.

01027 
01028     def mode(self, mode=None):
01029         """Set turtle-mode ('standard', 'logo' or 'world') and perform reset.
01030 
01031         Optional argument:
01032         mode -- on of the strings 'standard', 'logo' or 'world'
01033 
01034         Mode 'standard' is compatible with turtle.py.
01035         Mode 'logo' is compatible with most Logo-Turtle-Graphics.
01036         Mode 'world' uses userdefined 'worldcoordinates'. *Attention*: in
01037         this mode angles appear distorted if x/y unit-ratio doesn't equal 1.
01038         If mode is not given, return the current mode.
01039 
01040              Mode      Initial turtle heading     positive angles
01041          ------------|-------------------------|-------------------
01042           'standard'    to the right (east)       counterclockwise
01043             'logo'        upward    (north)         clockwise
01044 
01045         Examples:
01046         >>> mode('logo')   # resets turtle heading to north
01047         >>> mode()
01048         'logo'
01049         """
01050         if mode is None:
01051             return self._mode
01052         mode = mode.lower()
01053         if mode not in ["standard", "logo", "world"]:
01054             raise TurtleGraphicsError("No turtle-graphics-mode %s" % mode)
01055         self._mode = mode
01056         if mode in ["standard", "logo"]:
01057             self._setscrollregion(-self.canvwidth//2, -self.canvheight//2,
01058                                        self.canvwidth//2, self.canvheight//2)
01059             self.xscale = self.yscale = 1.0
01060         self.reset()

Here is the caller graph for this function:

def turtle.TurtleScreen.onclick (   self,
  fun,
  btn = 1,
  add = None 
)
Bind fun to mouse-click event on canvas.

Arguments:
fun -- a function with two arguments, the coordinates of the
       clicked point on the canvas.
num -- the number of the mouse-button, defaults to 1

Example (for a TurtleScreen instance named screen
and a Turtle instance named turtle):

>>> screen.onclick(turtle.goto)

### Subsequently clicking into the TurtleScreen will
### make the turtle move to the clicked point.
>>> screen.onclick(None)

### event-binding will be removed

Definition at line 1342 of file turtle.py.

01342 
01343     def onclick(self, fun, btn=1, add=None):
01344         """Bind fun to mouse-click event on canvas.
01345 
01346         Arguments:
01347         fun -- a function with two arguments, the coordinates of the
01348                clicked point on the canvas.
01349         num -- the number of the mouse-button, defaults to 1
01350 
01351         Example (for a TurtleScreen instance named screen
01352         and a Turtle instance named turtle):
01353 
01354         >>> screen.onclick(turtle.goto)
01355 
01356         ### Subsequently clicking into the TurtleScreen will
01357         ### make the turtle move to the clicked point.
01358         >>> screen.onclick(None)
01359 
01360         ### event-binding will be removed
01361         """
01362         self._onscreenclick(fun, btn, add)

Here is the caller graph for this function:

def turtle.TurtleScreen.onkey (   self,
  fun,
  key 
)
Bind fun to key-release event of key.

Arguments:
fun -- a function with no arguments
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")

In order to be able to register key-events, TurtleScreen
must have focus. (See method listen.)

Example (for a TurtleScreen instance named screen
and a Turtle instance named turtle):

>>> def f():
fd(50)
lt(60)


>>> screen.onkey(f, "Up")
>>> screen.listen()

### Subsequently the turtle can be moved by
### repeatedly pressing the up-arrow key,
### consequently drawing a hexagon

Definition at line 1363 of file turtle.py.

01363 
01364     def onkey(self, fun, key):
01365         """Bind fun to key-release event of key.
01366 
01367         Arguments:
01368         fun -- a function with no arguments
01369         key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
01370 
01371         In order to be able to register key-events, TurtleScreen
01372         must have focus. (See method listen.)
01373 
01374         Example (for a TurtleScreen instance named screen
01375         and a Turtle instance named turtle):
01376 
01377         >>> def f():
01378                 fd(50)
01379                 lt(60)
01380 
01381 
01382         >>> screen.onkey(f, "Up")
01383         >>> screen.listen()
01384 
01385         ### Subsequently the turtle can be moved by
01386         ### repeatedly pressing the up-arrow key,
01387         ### consequently drawing a hexagon
01388         """
01389         if fun is None:
01390             if key in self._keys:
01391                 self._keys.remove(key)
01392         elif key not in self._keys:
01393             self._keys.append(key)
01394         self._onkeyrelease(fun, key)

def turtle.TurtleScreen.onkeypress (   self,
  fun,
  key = None 
)
Bind fun to key-press event of key if key is given,
or to any key-press-event if no key is given.

Arguments:
fun -- a function with no arguments
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")

In order to be able to register key-events, TurtleScreen
must have focus. (See method listen.)

Example (for a TurtleScreen instance named screen
and a Turtle instance named turtle):

>>> def f():
fd(50)


>>> screen.onkey(f, "Up")
>>> screen.listen()

### Subsequently the turtle can be moved by
### repeatedly pressing the up-arrow key,
### or by keeping pressed the up-arrow key.
### consequently drawing a hexagon.

Definition at line 1395 of file turtle.py.

01395 
01396     def onkeypress(self, fun, key=None):
01397         """Bind fun to key-press event of key if key is given,
01398         or to any key-press-event if no key is given.
01399 
01400         Arguments:
01401         fun -- a function with no arguments
01402         key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
01403 
01404         In order to be able to register key-events, TurtleScreen
01405         must have focus. (See method listen.)
01406 
01407         Example (for a TurtleScreen instance named screen
01408         and a Turtle instance named turtle):
01409 
01410         >>> def f():
01411                 fd(50)
01412 
01413 
01414         >>> screen.onkey(f, "Up")
01415         >>> screen.listen()
01416 
01417         ### Subsequently the turtle can be moved by
01418         ### repeatedly pressing the up-arrow key,
01419         ### or by keeping pressed the up-arrow key.
01420         ### consequently drawing a hexagon.
01421         """
01422         if fun is None:
01423             if key in self._keys:
01424                 self._keys.remove(key)
01425         elif key is not None and key not in self._keys:
01426             self._keys.append(key)
01427         self._onkeypress(fun, key)

def turtle.TurtleScreen.ontimer (   self,
  fun,
  t = 0 
)
Install a timer, which calls fun after t milliseconds.

Arguments:
fun -- a function with no arguments.
t -- a number >= 0

Example (for a TurtleScreen instance named screen):

>>> running = True
>>> def f():
if running:
        fd(50)
        lt(60)
        screen.ontimer(f, 250)

>>> f()   ### makes the turtle marching around
>>> running = False

Definition at line 1440 of file turtle.py.

01440 
01441     def ontimer(self, fun, t=0):
01442         """Install a timer, which calls fun after t milliseconds.
01443 
01444         Arguments:
01445         fun -- a function with no arguments.
01446         t -- a number >= 0
01447 
01448         Example (for a TurtleScreen instance named screen):
01449 
01450         >>> running = True
01451         >>> def f():
01452                 if running:
01453                         fd(50)
01454                         lt(60)
01455                         screen.ontimer(f, 250)
01456 
01457         >>> f()   ### makes the turtle marching around
01458         >>> running = False
01459         """
01460         self._ontimer(fun, t)

def turtle.TurtleScreen.register_shape (   self,
  name,
  shape = None 
)
Adds a turtle shape to TurtleScreen's shapelist.

Arguments:
(1) name is the name of a gif-file and shape is None.
    Installs the corresponding image shape.
    !! Image-shapes DO NOT rotate when turning the turtle,
    !! so they do not display the heading of the turtle!
(2) name is an arbitrary string and shape is a tuple
    of pairs of coordinates. Installs the corresponding
    polygon shape
(3) name is an arbitrary string and shape is a
    (compound) Shape object. Installs the corresponding
    compound shape.
To use a shape, you have to issue the command shape(shapename).

call: register_shape("turtle.gif")
--or: register_shape("tri", ((0,0), (10,10), (-10,10)))

Example (for a TurtleScreen instance named screen):
>>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))

Definition at line 1100 of file turtle.py.

01100 
01101     def register_shape(self, name, shape=None):
01102         """Adds a turtle shape to TurtleScreen's shapelist.
01103 
01104         Arguments:
01105         (1) name is the name of a gif-file and shape is None.
01106             Installs the corresponding image shape.
01107             !! Image-shapes DO NOT rotate when turning the turtle,
01108             !! so they do not display the heading of the turtle!
01109         (2) name is an arbitrary string and shape is a tuple
01110             of pairs of coordinates. Installs the corresponding
01111             polygon shape
01112         (3) name is an arbitrary string and shape is a
01113             (compound) Shape object. Installs the corresponding
01114             compound shape.
01115         To use a shape, you have to issue the command shape(shapename).
01116 
01117         call: register_shape("turtle.gif")
01118         --or: register_shape("tri", ((0,0), (10,10), (-10,10)))
01119 
01120         Example (for a TurtleScreen instance named screen):
01121         >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
01122 
01123         """
01124         if shape is None:
01125             # image
01126             if name.lower().endswith(".gif"):
01127                 shape = Shape("image", self._image(name))
01128             else:
01129                 raise TurtleGraphicsError("Bad arguments for register_shape.\n"
01130                                           + "Use  help(register_shape)" )
01131         elif isinstance(shape, tuple):
01132             shape = Shape("polygon", shape)
01133         ## else shape assumed to be Shape-instance
01134         self._shapes[name] = shape

Here is the call graph for this function:

def turtle.TurtleScreen.reset (   self)
Reset all Turtles on the Screen to their initial state.

No argument.

Example (for a TurtleScreen instance named screen):
>>> screen.reset()

Definition at line 1194 of file turtle.py.

01194 
01195     def reset(self):
01196         """Reset all Turtles on the Screen to their initial state.
01197 
01198         No argument.
01199 
01200         Example (for a TurtleScreen instance named screen):
01201         >>> screen.reset()
01202         """
01203         for turtle in self._turtles:
01204             turtle._setmode(self._mode)
01205             turtle.reset()

Here is the caller graph for this function:

def turtle.TurtleScreen.screensize (   self,
  canvwidth = None,
  canvheight = None,
  bg = None 
)
Resize the canvas the turtles are drawing on.

Optional arguments:
canvwidth -- positive integer, new width of canvas in pixels
canvheight --  positive integer, new height of canvas in pixels
bg -- colorstring or color-tuple, new backgroundcolor
If no arguments are given, return current (canvaswidth, canvasheight)

Do not alter the drawing window. To observe hidden parts of
the canvas use the scrollbars. (Can make visible those parts
of a drawing, which were outside the canvas before!)

Example (for a Turtle instance named turtle):
>>> turtle.screensize(2000,1500)
    ### e. g. to search for an erroneously escaped turtle ;-)

Definition at line 1485 of file turtle.py.

01485 
01486     def screensize(self, canvwidth=None, canvheight=None, bg=None):
01487         """Resize the canvas the turtles are drawing on.
01488 
01489         Optional arguments:
01490         canvwidth -- positive integer, new width of canvas in pixels
01491         canvheight --  positive integer, new height of canvas in pixels
01492         bg -- colorstring or color-tuple, new backgroundcolor
01493         If no arguments are given, return current (canvaswidth, canvasheight)
01494 
01495         Do not alter the drawing window. To observe hidden parts of
01496         the canvas use the scrollbars. (Can make visible those parts
01497         of a drawing, which were outside the canvas before!)
01498 
01499         Example (for a Turtle instance named turtle):
01500         >>> turtle.screensize(2000,1500)
01501             ### e. g. to search for an erroneously escaped turtle ;-)
01502         """
01503         return self._resize(canvwidth, canvheight, bg)

Here is the caller graph for this function:

def turtle.TurtleScreen.setworldcoordinates (   self,
  llx,
  lly,
  urx,
  ury 
)
Set up a user defined coordinate-system.

Arguments:
llx -- a number, x-coordinate of lower left corner of canvas
lly -- a number, y-coordinate of lower left corner of canvas
urx -- a number, x-coordinate of upper right corner of canvas
ury -- a number, y-coordinate of upper right corner of canvas

Set up user coodinat-system and switch to mode 'world' if necessary.
This performs a screen.reset. If mode 'world' is already active,
all drawings are redrawn according to the new coordinates.

But ATTENTION: in user-defined coordinatesystems angles may appear
distorted. (see Screen.mode())

Example (for a TurtleScreen instance named screen):
>>> screen.setworldcoordinates(-10,-0.5,50,1.5)
>>> for _ in range(36):
left(10)
forward(0.5)

Definition at line 1061 of file turtle.py.

01061 
01062     def setworldcoordinates(self, llx, lly, urx, ury):
01063         """Set up a user defined coordinate-system.
01064 
01065         Arguments:
01066         llx -- a number, x-coordinate of lower left corner of canvas
01067         lly -- a number, y-coordinate of lower left corner of canvas
01068         urx -- a number, x-coordinate of upper right corner of canvas
01069         ury -- a number, y-coordinate of upper right corner of canvas
01070 
01071         Set up user coodinat-system and switch to mode 'world' if necessary.
01072         This performs a screen.reset. If mode 'world' is already active,
01073         all drawings are redrawn according to the new coordinates.
01074 
01075         But ATTENTION: in user-defined coordinatesystems angles may appear
01076         distorted. (see Screen.mode())
01077 
01078         Example (for a TurtleScreen instance named screen):
01079         >>> screen.setworldcoordinates(-10,-0.5,50,1.5)
01080         >>> for _ in range(36):
01081                 left(10)
01082                 forward(0.5)
01083         """
01084         if self.mode() != "world":
01085             self.mode("world")
01086         xspan = float(urx - llx)
01087         yspan = float(ury - lly)
01088         wx, wy = self._window_size()
01089         self.screensize(wx-20, wy-20)
01090         oldxscale, oldyscale = self.xscale, self.yscale
01091         self.xscale = self.canvwidth / xspan
01092         self.yscale = self.canvheight / yspan
01093         srx1 = llx * self.xscale
01094         sry1 = -ury * self.yscale
01095         srx2 = self.canvwidth + srx1
01096         sry2 = self.canvheight + sry1
01097         self._setscrollregion(srx1, sry1, srx2, sry2)
01098         self._rescale(self.xscale/oldxscale, self.yscale/oldyscale)
01099         self.update()

Here is the call graph for this function:

def turtle.TurtleScreen.tracer (   self,
  n = None,
  delay = None 
)
Turns turtle animation on/off and set delay for update drawings.

Optional arguments:
n -- nonnegative  integer
delay -- nonnegative  integer

If n is given, only each n-th regular screen update is really performed.
(Can be used to accelerate the drawing of complex graphics.)
Second arguments sets delay value (see RawTurtle.delay())

Example (for a TurtleScreen instance named screen):
>>> screen.tracer(8, 25)
>>> dist = 2
>>> for i in range(200):
fd(dist)
rt(90)
dist += 2

Definition at line 1238 of file turtle.py.

01238 
01239     def tracer(self, n=None, delay=None):
01240         """Turns turtle animation on/off and set delay for update drawings.
01241 
01242         Optional arguments:
01243         n -- nonnegative  integer
01244         delay -- nonnegative  integer
01245 
01246         If n is given, only each n-th regular screen update is really performed.
01247         (Can be used to accelerate the drawing of complex graphics.)
01248         Second arguments sets delay value (see RawTurtle.delay())
01249 
01250         Example (for a TurtleScreen instance named screen):
01251         >>> screen.tracer(8, 25)
01252         >>> dist = 2
01253         >>> for i in range(200):
01254                 fd(dist)
01255                 rt(90)
01256                 dist += 2
01257         """
01258         if n is None:
01259             return self._tracing
01260         self._tracing = int(n)
01261         self._updatecounter = 0
01262         if delay is not None:
01263             self._delayvalue = int(delay)
01264         if self._tracing:
01265             self.update()

Here is the call graph for this function:

Return the list of turtles on the screen.

Example (for a TurtleScreen instance named screen):
>>> screen.turtles()
[<turtle.Turtle object at 0x00E11FB0>]

Definition at line 1206 of file turtle.py.

01206 
01207     def turtles(self):
01208         """Return the list of turtles on the screen.
01209 
01210         Example (for a TurtleScreen instance named screen):
01211         >>> screen.turtles()
01212         [<turtle.Turtle object at 0x00E11FB0>]
01213         """
01214         return self._turtles

Perform a TurtleScreen update.

Definition at line 1290 of file turtle.py.

01290 
01291     def update(self):
01292         """Perform a TurtleScreen update.
01293         """
01294         tracing = self._tracing
01295         self._tracing = True
01296         for t in self.turtles():
01297             t._update_data()
01298             t._drawturtle()
01299         self._tracing = tracing
01300         self._update()

Here is the call graph for this function:

Here is the caller graph for this function:

Return the height of the turtle window.

Example (for a TurtleScreen instance named screen):
>>> screen.window_height()
480

Definition at line 1310 of file turtle.py.

01310 
01311     def window_height(self):
01312         """ Return the height of the turtle window.
01313 
01314         Example (for a TurtleScreen instance named screen):
01315         >>> screen.window_height()
01316         480
01317         """
01318         return self._window_size()[1]

Return the width of the turtle window.

Example (for a TurtleScreen instance named screen):
>>> screen.window_width()
640

Definition at line 1301 of file turtle.py.

01301 
01302     def window_width(self):
01303         """ Return the width of the turtle window.
01304 
01305         Example (for a TurtleScreen instance named screen):
01306         >>> screen.window_width()
01307         640
01308         """
01309         return self._window_size()[0]


Member Data Documentation

Definition at line 1013 of file turtle.py.

Definition at line 1014 of file turtle.py.

Definition at line 988 of file turtle.py.

Definition at line 993 of file turtle.py.

Definition at line 992 of file turtle.py.

Definition at line 994 of file turtle.py.

Definition at line 991 of file turtle.py.

turtle.TurtleScreen._RUNNING = True [static, private]

Definition at line 963 of file turtle.py.

Definition at line 967 of file turtle.py.

Definition at line 1015 of file turtle.py.

Definition at line 1017 of file turtle.py.

Definition at line 1016 of file turtle.py.

Definition at line 1507 of file turtle.py.

Definition at line 491 of file turtle.py.

Definition at line 490 of file turtle.py.

Definition at line 1506 of file turtle.py.

Definition at line 482 of file turtle.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 1508 of file turtle.py.

Definition at line 1504 of file turtle.py.

Definition at line 1505 of file turtle.py.

Reimplemented from turtle.TurtleScreenBase.

Definition at line 1058 of file turtle.py.

Reimplemented from turtle.TurtleScreenBase.

Definition at line 1058 of file turtle.py.


The documentation for this class was generated from the following file: