Back to index

python3.2  3.2.2
Classes | Functions | Variables
turtle Namespace Reference

Classes

class  Vec2D
class  ScrolledCanvas
class  _Root
class  TurtleScreenBase
class  Terminator
 End of Tkinter - interface ###. More...
class  TurtleGraphicsError
class  Shape
class  Tbuffer
class  TurtleScreen
class  TNavigator
class  TPen
class  _TurtleImage
class  RawTurtle
class  _Screen
class  Turtle

Functions

def config_dict
def readconfig
def __methodDict
 helper functions for Scrolled Canvas, to forward Canvas-methods to ScrolledCanvas class
def __methods
def __forwardmethods
def _onclick
 def _dot(self, pos, size, color): """may be implemented for some other graphics toolkit"""
def _onrelease
def _ondrag
def _onscreenclick
def _onkeyrelease
def _onkeypress
def _listen
def _ontimer
def _createimage
def _drawimage
def _setbgpic
def _type
def _pointlist
def _setscrollregion
def _rescale
def _resize
def _window_size
def mainloop
def textinput
def numinput
def speed
 three dummy methods to be implemented by child class:
def _tracer
def _delay
def _newLine
 three dummy methods to be implemented by child class:
def _update
def _color
def _colorstr
def Screen
 Screen - Singleton ########################.
def _getpen
def _getscreen
def write_docstringdict
def read_docstrings
def getmethparlist
def _turtle_docrevise
def _screen_docrevise
def switchpen
def demo1
def demo2

Variables

string _ver = "turtle 1.1b- - for Python 3.1 - 4. 5. 2009"
list _tg_classes
list _tg_screen_functions
list _tg_turtle_functions
list _tg_utilities = ['write_docstringdict', 'done']
tuple __all__
list _alias_list
dictionary _CFG
tuple __stringBody
 Canvas = TK.Canvas
 fd = forward
 bk = back
 backward = back
 rt = right
 lt = left
 position = pos
 setpos = goto
 setposition = goto
 seth = setheading
 width = pensize
 up = penup
 pu = penup
 pd = pendown
 down = pendown
 st = showturtle
 ht = hideturtle
 RawPen = RawTurtle
 Pen = Turtle
list _LANGUAGE = _CFG["language"]
tuple defstr
 The following mechanism makes all methods of RawTurtle and Turtle available as functions.
 done = mainloop
 canvwidth
 canvheight

Function Documentation

def turtle.__forwardmethods (   fromClass,
  toClass,
  toPart,
  exclude = () 
) [private]

Definition at line 308 of file turtle.py.

00308 
00309 def __forwardmethods(fromClass, toClass, toPart, exclude = ()):
00310     ### MANY CHANGES ###
00311     _dict_1 = {}
00312     __methodDict(toClass, _dict_1)
00313     _dict = {}
00314     mfc = __methods(fromClass)
00315     for ex in _dict_1.keys():
00316         if ex[:1] == '_' or ex[-1:] == '_' or ex in exclude or ex in mfc:
00317             pass
00318         else:
00319             _dict[ex] = _dict_1[ex]
00320 
00321     for method, func in _dict.items():
00322         d = {'method': method, 'func': func}
00323         if isinstance(toPart, str):
00324             execString = \
00325                 __stringBody % {'method' : method, 'attribute' : toPart}
00326         exec(execString, d)
00327         setattr(fromClass, method, d[method])   ### NEWU!
00328 

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.__methodDict (   cls,
  _dict 
) [private]

helper functions for Scrolled Canvas, to forward Canvas-methods to ScrolledCanvas class

helper function for Scrolled Canvas

Definition at line 288 of file turtle.py.

00288 
00289 def __methodDict(cls, _dict):
00290     """helper function for Scrolled Canvas"""
00291     baseList = list(cls.__bases__)
00292     baseList.reverse()
00293     for _super in baseList:
00294         __methodDict(_super, _dict)
00295     for key, value in cls.__dict__.items():
00296         if type(value) == types.FunctionType:
00297             _dict[key] = value

Here is the caller graph for this function:

def turtle.__methods (   cls) [private]
helper function for Scrolled Canvas

Definition at line 298 of file turtle.py.

00298 
00299 def __methods(cls):
00300     """helper function for Scrolled Canvas"""
00301     _dict = {}
00302     __methodDict(cls, _dict)
00303     return _dict.keys()

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle._color (   self,
  args 
) [private]
dummy method - to be overwritten by child class

Definition at line 2467 of file turtle.py.

02467 
02468     def _color(self, args):
        """dummy method - to be overwritten by child class"""
def turtle._colorstr (   self,
  args 
) [private]
dummy method - to be overwritten by child class

Definition at line 2469 of file turtle.py.

02469 
02470     def _colorstr(self, args):
02471         """dummy method - to be overwritten by child class"""

def turtle._createimage (   self,
  image 
) [private]
Create and return image item on canvas.

Definition at line 720 of file turtle.py.

00720 
00721     def _createimage(self, image):
00722         """Create and return image item on canvas.
00723         """
00724         return self.cv.create_image(0, 0, image=image)

def turtle._delay (   self,
  n = None 
) [private]
dummy method - to be overwritten by child class

Definition at line 2007 of file turtle.py.

02007 
02008     def _delay(self, n=None):
02009         """dummy method - to be overwritten by child class"""

def turtle._drawimage (   self,
  item,
  pos,
  image 
) [private]
Configure image item as to draw image object
at position (x,y) on canvas)

Definition at line 725 of file turtle.py.

00725 
00726     def _drawimage(self, item, pos, image):
00727         """Configure image item as to draw image object
00728         at position (x,y) on canvas)
00729         """
00730         x, y = pos
00731         self.cv.coords(item, (x * self.xscale, -y * self.yscale))
00732         self.cv.itemconfig(item, image=image)

def turtle._getpen ( ) [private]
Create the 'anonymous' turtle if not already present.

Definition at line 3820 of file turtle.py.

03820 
03821 def _getpen():
03822     """Create the 'anonymous' turtle if not already present."""
03823     if Turtle._pen is None:
03824         Turtle._pen = Turtle()
03825     return Turtle._pen

def turtle._getscreen ( ) [private]
Create a TurtleScreen if not already present.

Definition at line 3826 of file turtle.py.

03826 
03827 def _getscreen():
03828     """Create a TurtleScreen if not already present."""
03829     if Turtle._screen is None:
03830         Turtle._screen = Screen()
03831     return Turtle._screen

Here is the call graph for this function:

def turtle._listen (   self) [private]
Set focus on canvas (in order to collect key-events)

Definition at line 707 of file turtle.py.

00707 
00708     def _listen(self):
00709         """Set focus on canvas (in order to collect key-events)
00710         """
00711         self.cv.focus_force()

def turtle._newLine (   self,
  usePos = True 
) [private]

three dummy methods to be implemented by child class:

dummy method - to be overwritten by child class

Definition at line 2463 of file turtle.py.

02463 
02464     def _newLine(self, usePos = True):
        """dummy method - to be overwritten by child class"""
def turtle._onclick (   self,
  item,
  fun,
  num = 1,
  add = None 
) [private]

def _dot(self, pos, size, color): """may be implemented for some other graphics toolkit"""

Bind fun to mouse-click event on turtle.
fun must be a function with two arguments, the coordinates
of the clicked point on the canvas.
num, the number of the mouse-button defaults to 1

Definition at line 605 of file turtle.py.

00605 
00606     def _onclick(self, item, fun, num=1, add=None):
00607         """Bind fun to mouse-click event on turtle.
00608         fun must be a function with two arguments, the coordinates
00609         of the clicked point on the canvas.
00610         num, the number of the mouse-button defaults to 1
00611         """
00612         if fun is None:
00613             self.cv.tag_unbind(item, "<Button-%s>" % num)
00614         else:
00615             def eventfun(event):
00616                 x, y = (self.cv.canvasx(event.x)/self.xscale,
00617                         -self.cv.canvasy(event.y)/self.yscale)
00618                 fun(x, y)
00619             self.cv.tag_bind(item, "<Button-%s>" % num, eventfun, add)

def turtle._ondrag (   self,
  item,
  fun,
  num = 1,
  add = None 
) [private]
Bind fun to mouse-move-event (with pressed mouse button) on turtle.
fun must be a function with two arguments, the coordinates of the
actual mouse position on the canvas.
num, the number of the mouse-button defaults to 1

Every sequence of mouse-move-events on a turtle is preceded by a
mouse-click event on that turtle.

Definition at line 639 of file turtle.py.

00639 
00640     def _ondrag(self, item, fun, num=1, add=None):
00641         """Bind fun to mouse-move-event (with pressed mouse button) on turtle.
00642         fun must be a function with two arguments, the coordinates of the
00643         actual mouse position on the canvas.
00644         num, the number of the mouse-button defaults to 1
00645 
00646         Every sequence of mouse-move-events on a turtle is preceded by a
00647         mouse-click event on that turtle.
00648         """
00649         if fun is None:
00650             self.cv.tag_unbind(item, "<Button%s-Motion>" % num)
00651         else:
00652             def eventfun(event):
00653                 try:
00654                     x, y = (self.cv.canvasx(event.x)/self.xscale,
00655                            -self.cv.canvasy(event.y)/self.yscale)
00656                     fun(x, y)
00657                 except:
00658                     pass
00659             self.cv.tag_bind(item, "<Button%s-Motion>" % num, eventfun, add)

def turtle._onkeypress (   self,
  fun,
  key = None 
) [private]
If key is given, bind fun to key-press event of key.
Otherwise bind fun to any key-press.
Canvas must have focus. See method listen.

Definition at line 689 of file turtle.py.

00689 
00690     def _onkeypress(self, fun, key=None):
00691         """If key is given, bind fun to key-press event of key.
00692         Otherwise bind fun to any key-press.
00693         Canvas must have focus. See method listen.
00694         """
00695         if fun is None:
00696             if key is None:
00697                 self.cv.unbind("<KeyPress>", None)
00698             else:
00699                 self.cv.unbind("<KeyPress-%s>" % key, None)
00700         else:
00701             def eventfun(event):
00702                 fun()
00703             if key is None:
00704                 self.cv.bind("<KeyPress>", eventfun)
00705             else:
00706                 self.cv.bind("<KeyPress-%s>" % key, eventfun)

def turtle._onkeyrelease (   self,
  fun,
  key 
) [private]
Bind fun to key-release event of key.
Canvas must have focus. See method listen

Definition at line 678 of file turtle.py.

00678 
00679     def _onkeyrelease(self, fun, key):
00680         """Bind fun to key-release event of key.
00681         Canvas must have focus. See method listen
00682         """
00683         if fun is None:
00684             self.cv.unbind("<KeyRelease-%s>" % key, None)
00685         else:
00686             def eventfun(event):
00687                 fun()
00688             self.cv.bind("<KeyRelease-%s>" % key, eventfun)

def turtle._onrelease (   self,
  item,
  fun,
  num = 1,
  add = None 
) [private]
Bind fun to mouse-button-release event on turtle.
fun must be a function with two arguments, the coordinates
of the point on the canvas where mouse button is released.
num, the number of the mouse-button defaults to 1

If a turtle is clicked, first _onclick-event will be performed,
then _onscreensclick-event.

Definition at line 620 of file turtle.py.

00620 
00621     def _onrelease(self, item, fun, num=1, add=None):
00622         """Bind fun to mouse-button-release event on turtle.
00623         fun must be a function with two arguments, the coordinates
00624         of the point on the canvas where mouse button is released.
00625         num, the number of the mouse-button defaults to 1
00626 
00627         If a turtle is clicked, first _onclick-event will be performed,
00628         then _onscreensclick-event.
00629         """
00630         if fun is None:
00631             self.cv.tag_unbind(item, "<Button%s-ButtonRelease>" % num)
00632         else:
00633             def eventfun(event):
00634                 x, y = (self.cv.canvasx(event.x)/self.xscale,
00635                         -self.cv.canvasy(event.y)/self.yscale)
00636                 fun(x, y)
00637             self.cv.tag_bind(item, "<Button%s-ButtonRelease>" % num,
00638                              eventfun, add)

def turtle._onscreenclick (   self,
  fun,
  num = 1,
  add = None 
) [private]
Bind fun to mouse-click event on canvas.
fun must be a function with two arguments, the coordinates
of the clicked point on the canvas.
num, the number of the mouse-button defaults to 1

If a turtle is clicked, first _onclick-event will be performed,
then _onscreensclick-event.

Definition at line 660 of file turtle.py.

00660 
00661     def _onscreenclick(self, fun, num=1, add=None):
00662         """Bind fun to mouse-click event on canvas.
00663         fun must be a function with two arguments, the coordinates
00664         of the clicked point on the canvas.
00665         num, the number of the mouse-button defaults to 1
00666 
00667         If a turtle is clicked, first _onclick-event will be performed,
00668         then _onscreensclick-event.
00669         """
00670         if fun is None:
00671             self.cv.unbind("<Button-%s>" % num)
00672         else:
00673             def eventfun(event):
00674                 x, y = (self.cv.canvasx(event.x)/self.xscale,
00675                         -self.cv.canvasy(event.y)/self.yscale)
00676                 fun(x, y)
00677             self.cv.bind("<Button-%s>" % num, eventfun, add)

def turtle._ontimer (   self,
  fun,
  t 
) [private]
Install a timer, which calls fun after t milliseconds.

Definition at line 712 of file turtle.py.

00712 
00713     def _ontimer(self, fun, t):
00714         """Install a timer, which calls fun after t milliseconds.
00715         """
00716         if t == 0:
00717             self.cv.after_idle(fun)
00718         else:
00719             self.cv.after(t, fun)

def turtle._pointlist (   self,
  item 
) [private]
returns list of coordinate-pairs of points of item
Example (for insiders):
>>> from turtle import *
>>> getscreen()._pointlist(getturtle().turtle._item)
[(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
(9.9999999999999982, 0.0)]
>>> 

Definition at line 747 of file turtle.py.

00747 
00748     def _pointlist(self, item):
00749         """returns list of coordinate-pairs of points of item
00750         Example (for insiders):
00751         >>> from turtle import *
00752         >>> getscreen()._pointlist(getturtle().turtle._item)
00753         [(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
00754         (9.9999999999999982, 0.0)]
00755         >>> """
00756         cl = self.cv.coords(item)
00757         pl = [(cl[i], -cl[i+1]) for i in range(0, len(cl), 2)]
00758         return  pl

def turtle._rescale (   self,
  xscalefactor,
  yscalefactor 
) [private]

Definition at line 762 of file turtle.py.

00762 
00763     def _rescale(self, xscalefactor, yscalefactor):
00764         items = self.cv.find_all()
00765         for item in items:
00766             coordinates = list(self.cv.coords(item))
00767             newcoordlist = []
00768             while coordinates:
00769                 x, y = coordinates[:2]
00770                 newcoordlist.append(x * xscalefactor)
00771                 newcoordlist.append(y * yscalefactor)
00772                 coordinates = coordinates[2:]
00773             self.cv.coords(item, *newcoordlist)

def turtle._resize (   self,
  canvwidth = None,
  canvheight = None,
  bg = None 
) [private]
Resize the canvas the turtles are drawing on. Does
not alter the drawing window.

Definition at line 774 of file turtle.py.

00774 
00775     def _resize(self, canvwidth=None, canvheight=None, bg=None):
00776         """Resize the canvas the turtles are drawing on. Does
00777         not alter the drawing window.
00778         """
00779         # needs amendment
00780         if not isinstance(self.cv, ScrolledCanvas):
00781             return self.canvwidth, self.canvheight
00782         if canvwidth is canvheight is bg is None:
00783             return self.cv.canvwidth, self.cv.canvheight
00784         if canvwidth is not None:
00785             self.canvwidth = canvwidth
00786         if canvheight is not None:
00787             self.canvheight = canvheight
00788         self.cv.reset(canvwidth, canvheight, bg)

def turtle._screen_docrevise (   docstr) [private]
To reduce docstrings from TurtleScreen class for functions

Definition at line 3938 of file turtle.py.

03938 
03939 def _screen_docrevise(docstr):
03940     """To reduce docstrings from TurtleScreen class for functions
03941     """
03942     import re
03943     if docstr is None:
03944         return None
03945     screenname = _CFG["examplescreen"]
03946     newdocstr = docstr.replace("%s." % screenname,"")
03947     parexp = re.compile(r' \(.+ %s\):' % screenname)
03948     newdocstr = parexp.sub(":", newdocstr)
03949     return newdocstr

Here is the call graph for this function:

def turtle._setbgpic (   self,
  item,
  image 
) [private]
Configure image item as to draw image object
at center of canvas. Set item to the first item
in the displaylist, so it will be drawn below
any other item .

Definition at line 733 of file turtle.py.

00733 
00734     def _setbgpic(self, item, image):
00735         """Configure image item as to draw image object
00736         at center of canvas. Set item to the first item
00737         in the displaylist, so it will be drawn below
00738         any other item ."""
00739         self.cv.itemconfig(item, image=image)
00740         self.cv.tag_lower(item)

def turtle._setscrollregion (   self,
  srx1,
  sry1,
  srx2,
  sry2 
) [private]

Definition at line 759 of file turtle.py.

00759 
00760     def _setscrollregion(self, srx1, sry1, srx2, sry2):
00761         self.cv.config(scrollregion=(srx1, sry1, srx2, sry2))

def turtle._tracer (   self,
  a = None,
  b = None 
) [private]
dummy method - to be overwritten by child class

Definition at line 2005 of file turtle.py.

02005 
02006     def _tracer(self, a=None, b=None):
        """dummy method - to be overwritten by child class"""
def turtle._turtle_docrevise (   docstr) [private]
To reduce docstrings from RawTurtle class for functions

Definition at line 3926 of file turtle.py.

03926 
03927 def _turtle_docrevise(docstr):
03928     """To reduce docstrings from RawTurtle class for functions
03929     """
03930     import re
03931     if docstr is None:
03932         return None
03933     turtlename = _CFG["exampleturtle"]
03934     newdocstr = docstr.replace("%s." % turtlename,"")
03935     parexp = re.compile(r' \(.+ %s\):' % turtlename)
03936     newdocstr = parexp.sub(":", newdocstr)
03937     return newdocstr

Here is the call graph for this function:

def turtle._type (   self,
  item 
) [private]
Return 'line' or 'polygon' or 'image' depending on
type of item.

Definition at line 741 of file turtle.py.

00741 
00742     def _type(self, item):
00743         """Return 'line' or 'polygon' or 'image' depending on
00744         type of item.
00745         """
00746         return self.cv.type(item)

def turtle._update (   self,
  count = True,
  forced = False 
) [private]
dummy method - to be overwritten by child class

Definition at line 2465 of file turtle.py.

02465 
02466     def _update(self, count=True, forced=False):
        """dummy method - to be overwritten by child class"""
def turtle._window_size (   self) [private]
Return the width and height of the turtle window.

Definition at line 789 of file turtle.py.

00789 
00790     def _window_size(self):
00791         """ Return the width and height of the turtle window.
00792         """
00793         width = self.cv.winfo_width()
00794         if width <= 1:  # the window isn't managed by a geometry manager
00795             width = self.cv['width']
00796         height = self.cv.winfo_height()
00797         if height <= 1: # the window isn't managed by a geometry manager
00798             height = self.cv['height']
00799         return width, height

def turtle.config_dict (   filename)
Convert content of config-file into dictionary.

Definition at line 171 of file turtle.py.

00171 
00172 def config_dict(filename):
00173     """Convert content of config-file into dictionary."""
00174     with open(filename, "r") as f:
00175         cfglines = f.readlines()
00176     cfgdict = {}
00177     for line in cfglines:
00178         line = line.strip()
00179         if not line or line.startswith("#"):
00180             continue
00181         try:
00182             key, value = line.split("=")
00183         except:
00184             print("Bad line in config-file %s:\n%s" % (filename,line))
00185             continue
00186         key = key.strip()
00187         value = value.strip()
00188         if value in ["True", "False", "None", "''", '""']:
00189             value = eval(value)
00190         else:
00191             try:
00192                 if "." in value:
00193                     value = float(value)
00194                 else:
00195                     value = int(value)
00196             except:
00197                 pass # value need not be converted
00198         cfgdict[key] = value
00199     return cfgdict

Here is the caller graph for this function:

def turtle.demo1 ( )
Demo of old turtle.py - module

Definition at line 3985 of file turtle.py.

03985 
03986     def demo1():
03987         """Demo of old turtle.py - module"""
03988         reset()
03989         tracer(True)
03990         up()
03991         backward(100)
03992         down()
03993         # draw 3 squares; the last filled
03994         width(3)
03995         for i in range(3):
03996             if i == 2:
03997                 begin_fill()
03998             for _ in range(4):
03999                 forward(20)
04000                 left(90)
04001             if i == 2:
04002                 color("maroon")
04003                 end_fill()
04004             up()
04005             forward(30)
04006             down()
04007         width(1)
04008         color("black")
04009         # move out of the way
04010         tracer(False)
04011         up()
04012         right(90)
04013         forward(100)
04014         right(90)
04015         forward(100)
04016         right(180)
04017         down()
04018         # some text
04019         write("startstart", 1)
04020         write("start", 1)
04021         color("red")
04022         # staircase
04023         for i in range(5):
04024             forward(20)
04025             left(90)
04026             forward(20)
04027             right(90)
04028         # filled staircase
04029         tracer(True)
04030         begin_fill()
04031         for i in range(5):
04032             forward(20)
04033             left(90)
04034             forward(20)
04035             right(90)
04036         end_fill()
04037         # more text

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.demo2 ( )
Demo of some new features.

Definition at line 4038 of file turtle.py.

04038 
04039     def demo2():
04040         """Demo of some new features."""
04041         speed(1)
04042         st()
04043         pensize(3)
04044         setheading(towards(0, 0))
04045         radius = distance(0, 0)/2.0
04046         rt(90)
04047         for _ in range(18):
04048             switchpen()
04049             circle(radius, 10)
04050         write("wait a moment...")
04051         while undobufferentries():
04052             undo()
04053         reset()
04054         lt(90)
04055         colormode(255)
04056         laenge = 10
04057         pencolor("green")
04058         pensize(3)
04059         lt(180)
04060         for i in range(-2, 16):
04061             if i > 0:
04062                 begin_fill()
04063                 fillcolor(255-15*i, 0, 15*i)
04064             for _ in range(3):
04065                 fd(laenge)
04066                 lt(120)
04067             end_fill()
04068             laenge += 10
04069             lt(15)
04070             speed((speed()+1)%12)
04071         #end_fill()
04072 
04073         lt(120)
04074         pu()
04075         fd(70)
04076         rt(30)
04077         pd()
04078         color("red","yellow")
04079         speed(0)
04080         begin_fill()
04081         for _ in range(4):
04082             circle(50, 90)
04083             rt(90)
04084             fd(30)
04085             rt(90)
04086         end_fill()
04087         lt(90)
04088         pu()
04089         fd(30)
04090         pd()
04091         shape("turtle")
04092 
04093         tri = getturtle()
04094         tri.resizemode("auto")
04095         turtle = Turtle()
04096         turtle.resizemode("auto")
04097         turtle.shape("turtle")
04098         turtle.reset()
04099         turtle.left(90)
04100         turtle.speed(0)
04101         turtle.up()
04102         turtle.goto(280, 40)
04103         turtle.lt(30)
04104         turtle.down()
04105         turtle.speed(6)
04106         turtle.color("blue","orange")
04107         turtle.pensize(2)
04108         tri.speed(6)
04109         setheading(towards(turtle))
04110         count = 1
04111         while tri.distance(turtle) > 4:
04112             turtle.fd(3.5)
04113             turtle.lt(0.6)
04114             tri.setheading(tri.towards(turtle))
04115             tri.fd(4)
04116             if count % 20 == 0:
04117                 turtle.stamp()
04118                 tri.stamp()
04119                 switchpen()
04120             count += 1
04121         tri.write("CAUGHT! ", font=("Arial", 16, "bold"), align="right")
04122         tri.pencolor("black")
04123         tri.pencolor("red")
04124 
04125         def baba(xdummy, ydummy):
04126             clearscreen()
04127             bye()
04128 
04129         time.sleep(2)
04130 
04131         while undobufferentries():
04132             tri.undo()
04133             turtle.undo()
04134         tri.fd(50)
04135         tri.write("  Click me!", font = ("Courier", 12, "bold") )
04136         tri.onclick(baba, 1)

Here is the call graph for this function:

def turtle.getmethparlist (   ob)
Get strings describing the arguments for the given object

Returns a pair of strings representing function parameter lists
including parenthesis.  The first string is suitable for use in
function definition and the second is suitable for use in function
call.  The "self" parameter is not included.

Definition at line 3895 of file turtle.py.

03895 
03896 def getmethparlist(ob):
03897     """Get strings describing the arguments for the given object
03898 
03899     Returns a pair of strings representing function parameter lists
03900     including parenthesis.  The first string is suitable for use in
03901     function definition and the second is suitable for use in function
03902     call.  The "self" parameter is not included.
03903     """
03904     defText = callText = ""
03905     # bit of a hack for methods - turn it into a function
03906     # but we drop the "self" param.
03907     # Try and build one for Python defined functions
03908     args, varargs, varkw = inspect.getargs(ob.__code__)
03909     items2 = args[1:]
03910     realArgs = args[1:]
03911     defaults = ob.__defaults__ or []
03912     defaults = ["=%r" % (value,) for value in defaults]
03913     defaults = [""] * (len(realArgs)-len(defaults)) + defaults
03914     items1 = [arg + dflt for arg, dflt in zip(realArgs, defaults)]
03915     if varargs is not None:
03916         items1.append("*" + varargs)
03917         items2.append("*" + varargs)
03918     if varkw is not None:
03919         items1.append("**" + varkw)
03920         items2.append("**" + varkw)
03921     defText = ", ".join(items1)
03922     defText = "(%s)" % defText
03923     callText = ", ".join(items2)
03924     callText = "(%s)" % callText
03925     return defText, callText

Here is the call graph for this function:

Here is the caller graph for this function:

def turtle.mainloop (   self)
Starts event loop - calling Tkinter's mainloop function.

No argument.

Must be last statement in a turtle graphics program.
Must NOT be used if a script is run from within IDLE in -n mode
(No subprocess) - for interactive use of turtle graphics.

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

Definition at line 800 of file turtle.py.

00800 
00801     def mainloop(self):
00802         """Starts event loop - calling Tkinter's mainloop function.
00803 
00804         No argument.
00805 
00806         Must be last statement in a turtle graphics program.
00807         Must NOT be used if a script is run from within IDLE in -n mode
00808         (No subprocess) - for interactive use of turtle graphics.
00809 
00810         Example (for a TurtleScreen instance named screen):
00811         >>> screen.mainloop()
00812 
00813         """
00814         TK.mainloop()

Here is the caller graph for this function:

def turtle.numinput (   self,
  title,
  prompt,
  default = None,
  minval = None,
  maxval = None 
)
Pop up a dialog window for input of a number.

Arguments: title is the title of the dialog window,
prompt is a text mostly describing what numerical information to input.
default: default value
minval: minimum value for imput
maxval: maximum value for input

The number input must be in the range minval .. maxval if these are
given. If not, a hint is issued and the dialog remains open for
correction. Return the number input.
If the dialog is canceled,  return None.

Example (for a TurtleScreen instance named screen):
>>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)

Definition at line 830 of file turtle.py.

00830 
00831     def numinput(self, title, prompt, default=None, minval=None, maxval=None):
00832         """Pop up a dialog window for input of a number.
00833 
00834         Arguments: title is the title of the dialog window,
00835         prompt is a text mostly describing what numerical information to input.
00836         default: default value
00837         minval: minimum value for imput
00838         maxval: maximum value for input
00839 
00840         The number input must be in the range minval .. maxval if these are
00841         given. If not, a hint is issued and the dialog remains open for
00842         correction. Return the number input.
00843         If the dialog is canceled,  return None.
00844 
00845         Example (for a TurtleScreen instance named screen):
00846         >>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000)
00847 
00848         """
00849         return simpledialog.askfloat(title, prompt, initialvalue=default,
00850                                      minvalue=minval, maxvalue=maxval)
00851 

def turtle.read_docstrings (   lang)
Read in docstrings from lang-specific docstring dictionary.

Transfer docstrings, translated to lang, from a dictionary-file
to the methods of classes Screen and Turtle and - in revised form -
to the corresponding functions.

Definition at line 3866 of file turtle.py.

03866 
03867 def read_docstrings(lang):
03868     """Read in docstrings from lang-specific docstring dictionary.
03869 
03870     Transfer docstrings, translated to lang, from a dictionary-file
03871     to the methods of classes Screen and Turtle and - in revised form -
03872     to the corresponding functions.
03873     """
03874     modname = "turtle_docstringdict_%(language)s" % {'language':lang.lower()}
03875     module = __import__(modname)
03876     docsdict = module.docsdict
03877     for key in docsdict:
03878         try:
03879 #            eval(key).im_func.__doc__ = docsdict[key]
03880             eval(key).__doc__ = docsdict[key]
03881         except:
03882             print("Bad docstring-entry: %s" % key)

Here is the call graph for this function:

def turtle.readconfig (   cfgdict)
Read config-files, change configuration-dict accordingly.

If there is a turtle.cfg file in the current working directory,
read it from there. If this contains an importconfig-value,
say 'myway', construct filename turtle_mayway.cfg else use
turtle.cfg and read it from the import-directory, where
turtle.py is located.
Update configuration dictionary first according to config-file,
in the import directory, then according to config-file in the
current working directory.
If no config-file is found, the default configuration is used.

Definition at line 200 of file turtle.py.

00200 
00201 def readconfig(cfgdict):
00202     """Read config-files, change configuration-dict accordingly.
00203 
00204     If there is a turtle.cfg file in the current working directory,
00205     read it from there. If this contains an importconfig-value,
00206     say 'myway', construct filename turtle_mayway.cfg else use
00207     turtle.cfg and read it from the import-directory, where
00208     turtle.py is located.
00209     Update configuration dictionary first according to config-file,
00210     in the import directory, then according to config-file in the
00211     current working directory.
00212     If no config-file is found, the default configuration is used.
00213     """
00214     default_cfg = "turtle.cfg"
00215     cfgdict1 = {}
00216     cfgdict2 = {}
00217     if isfile(default_cfg):
00218         cfgdict1 = config_dict(default_cfg)
00219     if "importconfig" in cfgdict1:
00220         default_cfg = "turtle_%s.cfg" % cfgdict1["importconfig"]
00221     try:
00222         head, tail = split(__file__)
00223         cfg_file2 = join(head, default_cfg)
00224     except:
00225         cfg_file2 = ""
00226     if isfile(cfg_file2):
00227         cfgdict2 = config_dict(cfg_file2)
00228     _CFG.update(cfgdict2)
00229     _CFG.update(cfgdict1)
00230 
00231 try:
00232     readconfig(_CFG)
00233 except:
00234     print ("No configfile read, reason unknown")
00235 

Here is the call graph for this function:

def turtle.Screen ( )

Screen - Singleton ########################.

Return the singleton screen object.
If none exists at the moment, create a new one and return it,
else return the existing one.

Definition at line 3656 of file turtle.py.

03656 
03657 def Screen():
03658     """Return the singleton screen object.
03659     If none exists at the moment, create a new one and return it,
03660     else return the existing one."""
03661     if Turtle._screen is None:
03662         Turtle._screen = _Screen()
03663     return Turtle._screen

Here is the caller graph for this function:

def turtle.speed (   self,
  s = 0 
)

three dummy methods to be implemented by child class:

dummy method - to be overwritten by child class

Definition at line 2003 of file turtle.py.

02003 
02004     def speed(self, s=0):
        """dummy method - to be overwritten by child class"""

Here is the caller graph for this function:

Definition at line 3979 of file turtle.py.

03979 
03980     def switchpen():
03981         if isdown():
03982             pu()
03983         else:
03984             pd()

Here is the caller graph for this function:

def turtle.textinput (   self,
  title,
  prompt 
)
Pop up a dialog window for input of a string.

Arguments: title is the title of the dialog window,
prompt is a text mostly describing what information to input.

Return the string input
If the dialog is canceled, return None.

Example (for a TurtleScreen instance named screen):
>>> screen.textinput("NIM", "Name of first player:")

Definition at line 815 of file turtle.py.

00815 
00816     def textinput(self, title, prompt):
00817         """Pop up a dialog window for input of a string.
00818 
00819         Arguments: title is the title of the dialog window,
00820         prompt is a text mostly describing what information to input.
00821 
00822         Return the string input
00823         If the dialog is canceled, return None.
00824 
00825         Example (for a TurtleScreen instance named screen):
00826         >>> screen.textinput("NIM", "Name of first player:")
00827 
00828         """
00829         return simpledialog.askstring(title, prompt)

def turtle.write_docstringdict (   filename = "turtle_docstringdict")
Create and write docstring-dictionary to file.

Optional argument:
filename -- a string, used as filename
            default value is turtle_docstringdict

Has to be called explicitly, (not used by the turtle-graphics classes)
The docstring dictionary will be written to the Python script <filname>.py
It is intended to serve as a template for translation of the docstrings
into different languages.

Definition at line 3832 of file turtle.py.

03832 
03833 def write_docstringdict(filename="turtle_docstringdict"):
03834     """Create and write docstring-dictionary to file.
03835 
03836     Optional argument:
03837     filename -- a string, used as filename
03838                 default value is turtle_docstringdict
03839 
03840     Has to be called explicitly, (not used by the turtle-graphics classes)
03841     The docstring dictionary will be written to the Python script <filname>.py
03842     It is intended to serve as a template for translation of the docstrings
03843     into different languages.
03844     """
03845     docsdict = {}
03846 
03847     for methodname in _tg_screen_functions:
03848         key = "_Screen."+methodname
03849         docsdict[key] = eval(key).__doc__
03850     for methodname in _tg_turtle_functions:
03851         key = "Turtle."+methodname
03852         docsdict[key] = eval(key).__doc__
03853 
03854     f = open("%s.py" % filename,"w")
03855     keys = sorted([x for x in docsdict.keys()
03856                         if x.split('.')[1] not in _alias_list])
03857     f.write('docsdict = {\n\n')
03858     for key in keys[:-1]:
03859         f.write('%s :\n' % repr(key))
03860         f.write('        """%s\n""",\n\n' % docsdict[key])
03861     key = keys[-1]
03862     f.write('%s :\n' % repr(key))
03863     f.write('        """%s\n"""\n\n' % docsdict[key])
03864     f.write("}\n")
03865     f.close()

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
00002            _tg_utilities)

Definition at line 142 of file turtle.py.

Initial value:
00001 (
00002     'def %(method)s(self, *args, **kw): return ' +
00003     'self.%(attribute)s.%(method)s(*args, **kw)')

Definition at line 304 of file turtle.py.

Initial value:
00001 ['addshape', 'backward', 'bk', 'fd', 'ht', 'lt', 'pd', 'pos',
00002                'pu', 'rt', 'seth', 'setpos', 'setposition', 'st',
00003                'turtlesize', 'up', 'width']

Definition at line 145 of file turtle.py.

Initial value:
00001 {"width" : 0.5,               # Screen
00002         "height" : 0.75,
00003         "canvwidth" : 400,
00004         "canvheight": 300,
00005         "leftright": None,
00006         "topbottom": None,
00007         "mode": "standard",          # TurtleScreen
00008         "colormode": 1.0,
00009         "delay": 10,
00010         "undobuffersize": 1000,      # RawTurtle
00011         "shape": "classic",
00012         "pencolor" : "black",
00013         "fillcolor" : "black",
00014         "resizemode" : "noresize",
00015         "visible" : True,
00016         "language": "english",        # docstrings
00017         "exampleturtle": "turtle",
00018         "examplescreen": "screen",
00019         "title": "Python Turtle Graphics",
00020         "using_IDLE": False
00021        }

Definition at line 149 of file turtle.py.

list turtle._LANGUAGE = _CFG["language"]

Definition at line 3883 of file turtle.py.

Initial value:
00001 ['ScrolledCanvas', 'TurtleScreen', 'Screen',
00002                'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D']

Definition at line 118 of file turtle.py.

Initial value:
00001 ['addshape', 'bgcolor', 'bgpic', 'bye',
00002         'clearscreen', 'colormode', 'delay', 'exitonclick', 'getcanvas',
00003         'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
00004         'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer',
00005         'register_shape', 'resetscreen', 'screensize', 'setup',
00006         'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update',
00007         'window_height', 'window_width']

Definition at line 120 of file turtle.py.

Initial value:
00001 ['back', 'backward', 'begin_fill', 'begin_poly', 'bk',
00002         'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color',
00003         'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
00004         'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly',
00005         'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown',
00006         'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 'pd',
00007         'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position',
00008         'pu', 'radians', 'right', 'reset', 'resizemode', 'rt',
00009         'seth', 'setheading', 'setpos', 'setposition', 'settiltangle',
00010         'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle',
00011         'speed', 'st', 'stamp', 'tilt', 'tiltangle', 'towards',
00012         'turtlesize', 'undo', 'undobufferentries', 'up', 'width',
00013         'write', 'xcor', 'ycor']

Definition at line 127 of file turtle.py.

Definition at line 140 of file turtle.py.

string turtle._ver = "turtle 1.1b- - for Python 3.1 - 4. 5. 2009"

Definition at line 103 of file turtle.py.

Definition at line 2012 of file turtle.py.

turtle.bk = back

Definition at line 2011 of file turtle.py.

turtle.Canvas = TK.Canvas

Definition at line 455 of file turtle.py.

Definition at line 786 of file turtle.py.

Definition at line 784 of file turtle.py.

Initial value:
00001 ("def %(key)s%(pl1)s: return _getscreen().%(key)s%(pl2)s" %
00002                                    {'key':methodname, 'pl1':pl1, 'pl2':pl2})

The following mechanism makes all methods of RawTurtle and Turtle available as functions.

So we can enhance, change, add, delete methods to these classes and do not need to change anything here.

Definition at line 3960 of file turtle.py.

Definition at line 3976 of file turtle.py.

turtle.down = pendown

Definition at line 2476 of file turtle.py.

turtle.fd = forward

Definition at line 2010 of file turtle.py.

turtle.ht = hideturtle

Definition at line 2478 of file turtle.py.

Definition at line 2014 of file turtle.py.

turtle.pd = pendown

Definition at line 2475 of file turtle.py.

Definition at line 3818 of file turtle.py.

Definition at line 2015 of file turtle.py.

turtle.pu = penup

Definition at line 2474 of file turtle.py.

Definition at line 3652 of file turtle.py.

Definition at line 2013 of file turtle.py.

turtle.seth = setheading

Definition at line 2018 of file turtle.py.

turtle.setpos = goto

Definition at line 2016 of file turtle.py.

Definition at line 2017 of file turtle.py.

turtle.st = showturtle

Definition at line 2477 of file turtle.py.

turtle.up = penup

Definition at line 2473 of file turtle.py.

turtle.width = pensize

Definition at line 2472 of file turtle.py.