desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Return the angle of the line from the turtle\'s position to (x, y). Arguments: x -- a number or a pair/vector of numbers or a turtle instance y -- a number None None call: distance(x, y) # two coordinates --or: distance((x, y)) # a pair (tuple) of coordinates --or:...
def towards(self, x, y=None):
if (y is not None): pos = Vec2D(x, y) if isinstance(x, Vec2D): pos = x elif isinstance(x, tuple): pos = Vec2D(*x) elif isinstance(x, TNavigator): pos = x._position (x, y) = (pos - self._position) result = (round(((math.atan2(y, x) * 180.0) / math.pi), 10) % 360.0)...
'Return the turtle\'s current heading. No arguments. Example (for a Turtle instance named turtle): >>> turtle.left(67) >>> turtle.heading() 67.0'
def heading(self):
(x, y) = self._orient result = (round(((math.atan2(y, x) * 180.0) / math.pi), 10) % 360.0) result /= self._degreesPerAU return ((self._angleOffset + (self._angleOrient * result)) % self._fullcircle)
'Set the orientation of the turtle to to_angle. Aliases: setheading | seth Argument: to_angle -- a number (integer or float) Set the orientation of the turtle to to_angle. Here are some common directions in degrees: standard - mode: logo-mode: 0 - east 0 - north 90 - north 90 - eas...
def setheading(self, to_angle):
angle = ((to_angle - self.heading()) * self._angleOrient) full = self._fullcircle angle = (((angle + (full / 2.0)) % full) - (full / 2.0)) self._rotate(angle)
'Draw a circle with given radius. Arguments: radius -- a number extent (optional) -- a number steps (optional) -- an integer Draw a circle with given radius. The center is radius units left of the turtle; extent - an angle - determines which part of the circle is drawn. If extent is not given, draw the entire circle. I...
def circle(self, radius, extent=None, steps=None):
if self.undobuffer: self.undobuffer.push(['seq']) self.undobuffer.cumulate = True speed = self.speed() if (extent is None): extent = self._fullcircle if (steps is None): frac = (abs(extent) / self._fullcircle) steps = (1 + int((min((11 + (abs(radius) / 6.0)), 59.0...
'Set resizemode to one of the values: "auto", "user", "noresize". (Optional) Argument: rmode -- one of the strings "auto", "user", "noresize" Different resizemodes have the following effects: - "auto" adapts the appearance of the turtle corresponding to the value of pensize. - "user" adapts the appearance of the turtle...
def resizemode(self, rmode=None):
if (rmode is None): return self._resizemode rmode = rmode.lower() if (rmode in ['auto', 'user', 'noresize']): self.pen(resizemode=rmode)
'Set or return the line thickness. Aliases: pensize | width Argument: width -- positive number Set the line thickness to width or return it. If resizemode is set to "auto" and turtleshape is a polygon, that polygon is drawn with the same line thickness. If no argument is given, current pensize is returned. Example (fo...
def pensize(self, width=None):
if (width is None): return self._pensize self.pen(pensize=width)
'Pull the pen up -- no drawing when moving. Aliases: penup | pu | up No argument Example (for a Turtle instance named turtle): >>> turtle.penup()'
def penup(self):
if (not self._drawing): return self.pen(pendown=False)
'Pull the pen down -- drawing when moving. Aliases: pendown | pd | down No argument. Example (for a Turtle instance named turtle): >>> turtle.pendown()'
def pendown(self):
if self._drawing: return self.pen(pendown=True)
'Return True if pen is down, False if it\'s up. No argument. Example (for a Turtle instance named turtle): >>> turtle.penup() >>> turtle.isdown() False >>> turtle.pendown() >>> turtle.isdown() True'
def isdown(self):
return self._drawing
'Return or set the turtle\'s speed. Optional argument: speed -- an integer in the range 0..10 or a speedstring (see below) Set the turtle\'s speed to an integer value in the range 0 .. 10. If no argument is given: return current speed. If input is a number greater than 10 or smaller than 0.5, speed is set to 0. Speedst...
def speed(self, speed=None):
speeds = {'fastest': 0, 'fast': 10, 'normal': 6, 'slow': 3, 'slowest': 1} if (speed is None): return self._speed if (speed in speeds): speed = speeds[speed] elif (0.5 < speed < 10.5): speed = int(round(speed)) else: speed = 0 self.pen(speed=speed)
'Return or set the pencolor and fillcolor. Arguments: Several input formats are allowed. They use 0, 1, 2, or 3 arguments as follows: color() Return the current pencolor and the current fillcolor as a pair of color specification strings as are returned by pencolor and fillcolor. color(colorstring), color((r,g,b)), colo...
def color(self, *args):
if args: l = len(args) if (l == 1): pcolor = fcolor = args[0] elif (l == 2): (pcolor, fcolor) = args elif (l == 3): pcolor = fcolor = args pcolor = self._colorstr(pcolor) fcolor = self._colorstr(fcolor) self.pen(pencolor=pco...
'Return or set the pencolor. Arguments: Four input formats are allowed: - pencolor() Return the current pencolor as color specification string, possibly in hex-number format (see example). May be used as input to another color/pencolor/fillcolor call. - pencolor(colorstring) s is a Tk color specification string, such a...
def pencolor(self, *args):
if args: color = self._colorstr(args) if (color == self._pencolor): return self.pen(pencolor=color) else: return self._color(self._pencolor)
'Return or set the fillcolor. Arguments: Four input formats are allowed: - fillcolor() Return the current fillcolor as color specification string, possibly in hex-number format (see example). May be used as input to another color/pencolor/fillcolor call. - fillcolor(colorstring) s is a Tk color specification string, su...
def fillcolor(self, *args):
if args: color = self._colorstr(args) if (color == self._fillcolor): return self.pen(fillcolor=color) else: return self._color(self._fillcolor)
'Makes the turtle visible. Aliases: showturtle | st No argument. Example (for a Turtle instance named turtle): >>> turtle.hideturtle() >>> turtle.showturtle()'
def showturtle(self):
self.pen(shown=True)
'Makes the turtle invisible. Aliases: hideturtle | ht No argument. It\'s a good idea to do this while you\'re in the middle of a complicated drawing, because hiding the turtle speeds up the drawing observably. Example (for a Turtle instance named turtle): >>> turtle.hideturtle()'
def hideturtle(self):
self.pen(shown=False)
'Return True if the Turtle is shown, False if it\'s hidden. No argument. Example (for a Turtle instance named turtle): >>> turtle.hideturtle() >>> print turtle.isvisible(): False'
def isvisible(self):
return self._shown
'Return or set the pen\'s attributes. Arguments: pen -- a dictionary with some or all of the below listed keys. **pendict -- one or more keyword-arguments with the below listed keys as keywords. Return or set the pen\'s attributes in a \'pen-dictionary\' with the following key/value pairs: "shown" : True/False "...
def pen(self, pen=None, **pendict):
_pd = {'shown': self._shown, 'pendown': self._drawing, 'pencolor': self._pencolor, 'fillcolor': self._fillcolor, 'pensize': self._pensize, 'speed': self._speed, 'resizemode': self._resizemode, 'stretchfactor': self._stretchfactor, 'outline': self._outlinewidth, 'tilt': self._tilt} if (not (pen or pendict)): ...
'Delete the turtle\'s drawings and restore its default values. No argument. Delete the turtle\'s drawings from the screen, re-center the turtle and set variables to the default values. Example (for a Turtle instance named turtle): >>> turtle.position() (0.00,-22.00) >>> turtle.heading() 100.0 >>> turtle.reset() >>> tur...
def reset(self):
TNavigator.reset(self) TPen._reset(self) self._clear() self._drawturtle() self._update()
'Set or disable undobuffer. Argument: size -- an integer or None If size is an integer an empty undobuffer of given size is installed. Size gives the maximum number of turtle-actions that can be undone by the undo() function. If size is None, no undobuffer is present. Example (for a Turtle instance named turtle): >>> t...
def setundobuffer(self, size):
if (size is None): self.undobuffer = None else: self.undobuffer = Tbuffer(size)
'Return count of entries in the undobuffer. No argument. Example (for a Turtle instance named turtle): >>> while undobufferentries(): undo()'
def undobufferentries(self):
if (self.undobuffer is None): return 0 return self.undobuffer.nr_of_items()
'Delete all of pen\'s drawings'
def _clear(self):
self._fillitem = self._fillpath = None for item in self.items: self.screen._delete(item) self.currentLineItem = self.screen._createline() self.currentLine = [] if self._drawing: self.currentLine.append(self._position) self.items = [self.currentLineItem] self.clearstamps() ...
'Delete the turtle\'s drawings from the screen. Do not move turtle. No arguments. Delete the turtle\'s drawings from the screen. Do not move turtle. State and position of the turtle as well as drawings of other turtles are not affected. Examples (for a Turtle instance named turtle): >>> turtle.clear()'
def clear(self):
self._clear() self._update()
'Perform a Turtle-data update.'
def _update(self):
screen = self.screen if (screen._tracing == 0): return elif (screen._tracing == 1): self._update_data() self._drawturtle() screen._update() screen._delay(screen._delayvalue) else: self._update_data() if (screen._updatecounter == 0): for...
'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 RawTu...
def tracer(self, flag=None, delay=None):
return self.screen.tracer(flag, delay)
'Convert colortriples to hexstrings.'
def _cc(self, args):
if isinstance(args, str): return args try: (r, g, b) = args except: raise TurtleGraphicsError(('bad color arguments: %s' % str(args))) if (self.screen._colormode == 1.0): (r, g, b) = [round((255.0 * x)) for x in (r, g, b)] if (not ((0 <= r <= 255) and (0 <= g...
'Create and return a clone of the turtle. No argument. Create and return a clone of the turtle with same position, heading and turtle properties. Example (for a Turtle instance named mick): mick = Turtle() joe = mick.clone()'
def clone(self):
screen = self.screen self._newLine(self._drawing) turtle = self.turtle self.screen = None self.turtle = None q = deepcopy(self) self.screen = screen self.turtle = turtle q.screen = screen q.turtle = _TurtleImage(screen, self.turtle.shapeIndex) screen._turtles.append(q) tt...
'Set turtle shape to shape with given name / return current shapename. Optional argument: name -- a string, which is a valid shapename Set turtle shape to shape with given name or, if name is not given, return name of current shape. Shape with name must exist in the TurtleScreen\'s shape dictionary. Initially there are...
def shape(self, name=None):
if (name is None): return self.turtle.shapeIndex if (not (name in self.screen.getshapes())): raise TurtleGraphicsError(('There is no shape named %s' % name)) self.turtle._setshape(name) self._update()
'Set/return turtle\'s stretchfactors/outline. Set resizemode to "user". Optinonal arguments: stretch_wid : positive number stretch_len : positive number outline : positive number Return or set the pen\'s attributes x/y-stretchfactors and/or outline. Set resizemode to "user". If and only if resizemode is set to "user",...
def shapesize(self, stretch_wid=None, stretch_len=None, outline=None):
if (stretch_wid is stretch_len is outline is None): (stretch_wid, stretch_len) = self._stretchfactor return (stretch_wid, stretch_len, self._outlinewidth) if (stretch_wid is not None): if (stretch_len is None): stretchfactor = (stretch_wid, stretch_wid) else: ...
'Rotate the turtleshape to point in the specified direction Optional argument: angle -- number Rotate the turtleshape to point in the direction specified by angle, regardless of its current tilt-angle. DO NOT change the turtle\'s heading (direction of movement). Examples (for a Turtle instance named turtle): >>> turtle...
def settiltangle(self, angle):
tilt = (((- angle) * self._degreesPerAU) * self._angleOrient) tilt = (((tilt * math.pi) / 180.0) % (2 * math.pi)) self.pen(resizemode='user', tilt=tilt)
'Return the current tilt-angle. No argument. Return the current tilt-angle, i. e. the angle between the orientation of the turtleshape and the heading of the turtle (its direction of movement). Examples (for a Turtle instance named turtle): >>> turtle.shape("circle") >>> turtle.shapesize(5,2) >>> turtle.tilt(45) >>> tu...
def tiltangle(self):
tilt = (((- self._tilt) * (180.0 / math.pi)) * self._angleOrient) return ((tilt / self._degreesPerAU) % self._fullcircle)
'Rotate the turtleshape by angle. Argument: angle - a number Rotate the turtleshape by angle from its current tilt-angle, but do NOT change the turtle\'s heading (direction of movement). Examples (for a Turtle instance named turtle): >>> turtle.shape("circle") >>> turtle.shapesize(5,2) >>> turtle.tilt(30) >>> turtle.fd...
def tilt(self, angle):
self.settiltangle((angle + self.tiltangle()))
'Computes transformed polygon shapes from a shape according to current position and heading.'
def _polytrafo(self, poly):
screen = self.screen (p0, p1) = self._position (e0, e1) = self._orient e = Vec2D(e0, ((e1 * screen.yscale) / screen.xscale)) (e0, e1) = ((1.0 / abs(e)) * e) return [((p0 + (((e1 * x) + (e0 * y)) / screen.xscale)), (p1 + ((((- e0) * x) + (e1 * y)) / screen.yscale))) for (x, y) in poly]
'Manages the correct rendering of the turtle with respect to its shape, resizemode, stretch and tilt etc.'
def _drawturtle(self):
screen = self.screen shape = screen._shapes[self.turtle.shapeIndex] ttype = shape._type titem = self.turtle._item if (self._shown and (screen._updatecounter == 0) and (screen._tracing > 0)): self._hidden_from_screen = False tshape = shape._data if (ttype == 'polygon'): ...
'Stamp a copy of the turtleshape onto the canvas and return its id. No argument. 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). Example (for a Turtle instance named turtle): >>> turtle.col...
def stamp(self):
screen = self.screen shape = screen._shapes[self.turtle.shapeIndex] ttype = shape._type tshape = shape._data if (ttype == 'polygon'): stitem = screen._createpoly() if (self._resizemode == 'noresize'): w = 1 shape = tshape else: if (self._re...
'does the work for clearstamp() and clearstamps()'
def _clearstamp(self, stampid):
if (stampid in self.stampItems): if isinstance(stampid, tuple): for subitem in stampid: self.screen._delete(subitem) else: self.screen._delete(stampid) self.stampItems.remove(stampid) item = ('stamp', stampid) buf = self.undobuffer if (item...
'Delete stamp with given stampid Argument: stampid - an integer, must be return value of previous stamp() call. Example (for a Turtle instance named turtle): >>> turtle.color("blue") >>> astamp = turtle.stamp() >>> turtle.fd(50) >>> turtle.clearstamp(astamp)'
def clearstamp(self, stampid):
self._clearstamp(stampid) self._update()
'Delete all or first/last n of turtle\'s stamps. Optional argument: n -- an integer If n is None, delete all of pen\'s stamps, else if n > 0 delete first n stamps else if n < 0 delete last n stamps. Example (for a Turtle instance named turtle): >>> for i in range(8): turtle.stamp(); turtle.fd(30) >>> turtle.clearstamps...
def clearstamps(self, n=None):
if (n is None): toDelete = self.stampItems[:] elif (n >= 0): toDelete = self.stampItems[:n] else: toDelete = self.stampItems[n:] for item in toDelete: self._clearstamp(item) self._update()
'Move the pen to the point end, thereby drawing a line if pen is down. All other methodes for turtle movement depend on this one.'
def _goto(self, end):
go_modes = (self._drawing, self._pencolor, self._pensize, isinstance(self._fillpath, list)) screen = self.screen undo_entry = ('go', self._position, end, go_modes, (self.currentLineItem, self.currentLine[:], screen._pointlist(self.currentLineItem), self.items[:])) if self.undobuffer: self.undobu...
'Reverse a _goto. Used for undo()'
def _undogoto(self, entry):
(old, new, go_modes, coodata) = entry (drawing, pc, ps, filling) = go_modes (cLI, cL, pl, items) = coodata screen = self.screen if (abs((self._position - new)) > 0.5): print 'undogoto: HALLO-DA-STIMMT-WAS-NICHT!' self.currentLineItem = cLI self.currentLine = cL if (pl == [(0, ...
'Turns pen clockwise by angle.'
def _rotate(self, angle):
if self.undobuffer: self.undobuffer.push(('rot', angle, self._degreesPerAU)) angle *= self._degreesPerAU neworient = self._orient.rotate(angle) tracing = self.screen._tracing if ((tracing == 1) and (self._speed > 0)): anglevel = (3.0 * self._speed) steps = (1 + int((abs(angle...
'Closes current line item and starts a new one. Remark: if current line became too long, animation performance (via _drawline) slowed down considerably.'
def _newLine(self, usePos=True):
if (len(self.currentLine) > 1): self.screen._drawline(self.currentLineItem, self.currentLine, self._pencolor, self._pensize) self.currentLineItem = self.screen._createline() self.items.append(self.currentLineItem) else: self.screen._drawline(self.currentLineItem, top=True) se...
'Call fill(True) before drawing a shape to fill, fill(False) when done. Optional argument: flag -- True/False (or 1/0 respectively) Call fill(True) before drawing the shape you want to fill, and fill(False) when done. When used without argument: return fillstate (True if filling, False else) Example (for a Turtle inst...
def fill(self, flag=None):
filling = isinstance(self._fillpath, list) if (flag is None): return filling screen = self.screen entry1 = entry2 = () if filling: if (len(self._fillpath) > 2): self.screen._drawpoly(self._fillitem, self._fillpath, fill=self._fillcolor) entry1 = ('dofill', sel...
'Called just before drawing a shape to be filled. No argument. Example (for a Turtle instance named turtle): >>> turtle.begin_fill() >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.end_fill()'
def begin_fill(self):
self.fill(True)
'Fill the shape drawn after the call begin_fill(). No argument. Example (for a Turtle instance named turtle): >>> turtle.begin_fill() >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.end_fill()'
def end_fill(self):
self.fill(False)
'Draw a dot with diameter size, using color. Optional arguments: size -- an integer >= 1 (if given) color -- a colorstring or a numeric color tuple Draw a circular dot with diameter size, using color. If size is not given, the maximum of pensize+4 and 2*pensize is used. Example (for a Turtle instance named turtle): >>>...
def dot(self, size=None, *color):
if (not color): if isinstance(size, (str, tuple)): color = self._colorstr(size) size = (self._pensize + max(self._pensize, 4)) else: color = self._pencolor if (not size): size = (self._pensize + max(self._pensize, 4)) else: ...
'Performs the writing for write()'
def _write(self, txt, align, font):
(item, end) = self.screen._write(self._position, txt, align, font, self._pencolor) self.items.append(item) if self.undobuffer: self.undobuffer.push(('wri', item)) return end
'Write text at the current turtle position. Arguments: arg -- info, which is to be written to the TurtleScreen move (optional) -- True/False align (optional) -- one of the strings "left", "center" or right" font (optional) -- a triple (fontname, fontsize, fonttype) Write text - the string representation of arg - at the...
def write(self, arg, move=False, align='left', font=('Arial', 8, 'normal')):
if self.undobuffer: self.undobuffer.push(['seq']) self.undobuffer.cumulate = True end = self._write(str(arg), align.lower(), font) if move: (x, y) = self.pos() self.setpos(end, y) if self.undobuffer: self.undobuffer.cumulate = False
'Start recording the vertices of a polygon. No argument. Start recording the vertices of a polygon. Current turtle position is first point of polygon. Example (for a Turtle instance named turtle): >>> turtle.begin_poly()'
def begin_poly(self):
self._poly = [self._position] self._creatingPoly = True
'Stop recording the vertices of a polygon. No argument. Stop recording the vertices of a polygon. Current turtle position is last point of polygon. This will be connected with the first point. Example (for a Turtle instance named turtle): >>> turtle.end_poly()'
def end_poly(self):
self._creatingPoly = False
'Return the lastly recorded polygon. No argument. Example (for a Turtle instance named turtle): >>> p = turtle.get_poly() >>> turtle.register_shape("myFavouriteShape", p)'
def get_poly(self):
if (self._poly is not None): return tuple(self._poly)
'Return the TurtleScreen object, the turtle is drawing on. No argument. Return the TurtleScreen object, the turtle is drawing on. So TurtleScreen-methods can be called for that object. Example (for a Turtle instance named turtle): >>> ts = turtle.getscreen() >>> ts <turtle.TurtleScreen object at 0x0106B770> >>> ts.bg...
def getscreen(self):
return self.screen
'Return the Turtleobject itself. No argument. Only reasonable use: as a function to return the \'anonymous turtle\': Example: >>> pet = getturtle() >>> pet.fd(50) >>> pet <turtle.Turtle object at 0x0187D810> >>> turtles() [<turtle.Turtle object at 0x0187D810>]'
def getturtle(self):
return self
'Returns the width of the turtle window. No argument. Example (for a TurtleScreen instance named screen): >>> screen.window_width() 640'
def window_width(self):
return self.screen._window_size()[0]
'Return the height of the turtle window. No argument. Example (for a TurtleScreen instance named screen): >>> screen.window_height() 480'
def window_height(self):
return self.screen._window_size()[1]
'Set delay value which determines speed of turtle animation.'
def _delay(self, delay=None):
return self.screen.delay(delay)
'Bind fun to mouse-click event on this turtle on canvas. Arguments: fun -- a function with two arguments, to which will be assigned the coordinates of the clicked point on the canvas. num -- number of the mouse-button defaults to 1 (left mouse button). add -- True or False. If True, new binding will be added, otherw...
def onclick(self, fun, btn=1, add=None):
self.screen._onclick(self.turtle._item, fun, btn, add) self._update()
'Bind fun to mouse-button-release event on this turtle on canvas. Arguments: fun -- a function with two arguments, to which will be assigned the coordinates of the clicked point on the canvas. num -- number of the mouse-button defaults to 1 (left mouse button). Example (for a MyTurtle instance named joe): >>> class My...
def onrelease(self, fun, btn=1, add=None):
self.screen._onrelease(self.turtle._item, fun, btn, add) self._update()
'Bind fun to mouse-move event on this turtle on canvas. Arguments: fun -- a function with two arguments, to which will be assigned the coordinates of the clicked point on the canvas. num -- number of the mouse-button defaults to 1 (left mouse button). Every sequence of mouse-move-events on a turtle is preceded by a mou...
def ondrag(self, fun, btn=1, add=None):
self.screen._ondrag(self.turtle._item, fun, btn, add)
'Does the main part of the work for undo()'
def _undo(self, action, data):
if (self.undobuffer is None): return if (action == 'rot'): (angle, degPAU) = data self._rotate((((- angle) * degPAU) / self._degreesPerAU)) dummy = self.undobuffer.pop() elif (action == 'stamp'): stitem = data[0] self.clearstamp(stitem) elif (action == 'go...
'undo (repeatedly) the last turtle action. No argument. undo (repeatedly) the last turtle action. Number of available undo actions is determined by the size of the undobuffer. Example (for a Turtle instance named turtle): >>> for i in range(4): turtle.fd(50); turtle.lt(80) >>> for i in range(8): turtle.undo()'
def undo(self):
if (self.undobuffer is None): return item = self.undobuffer.pop() action = item[0] data = item[1:] if (action == 'seq'): while data: item = data.pop() self._undo(item[0], item[1:]) else: self._undo(action, data)
'Set the size and position of the main window. Arguments: width: as integer a size in pixels, as float a fraction of the screen. Default is 50% of screen. height: as integer the height in pixels, as float a fraction of the screen. Default is 75% of screen. startx: if positive, starting position in pixels from the left ...
def setup(self, width=_CFG['width'], height=_CFG['height'], startx=_CFG['leftright'], starty=_CFG['topbottom']):
if (not hasattr(self._root, 'set_geometry')): return sw = self._root.win_width() sh = self._root.win_height() if (isinstance(width, float) and (0 <= width <= 1)): width = (sw * width) if (startx is None): startx = ((sw - width) / 2) if (isinstance(height, float) and (0 <=...
'Set title of turtle-window Argument: titlestring -- a string, to appear in the titlebar of the turtle graphics window. This is a method of Screen-class. Not available for TurtleScreen- objects. Example (for a Screen instance named screen): >>> screen.title("Welcome to the turtle-zoo!")'
def title(self, titlestring):
if (_Screen._root is not None): _Screen._root.title(titlestring) _Screen._title = titlestring
'Shut the turtlegraphics window. Example (for a TurtleScreen instance named screen): >>> screen.bye()'
def bye(self):
self._destroy()
'Go into mainloop until the mouse is clicked. No arguments. Bind bye() method to mouseclick on TurtleScreen. If "using_IDLE" - value in configuration dictionary is False (default value), enter mainloop. If IDLE with -n switch (no subprocess) is used, this value should be set to True in turtle.cfg. In this case IDLE\'s ...
def exitonclick(self):
def exitGracefully(x, y): 'Screen.bye() with two dummy-parameters' self.bye() self.onclick(exitGracefully) if _CFG['using_IDLE']: return try: mainloop() except AttributeError: exit(0)
'Construct a variable MASTER can be given as master widget. VALUE is an optional value (defaults to "") NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.'
def __init__(self, master=None, value=None, name=None):
global _varnum if (not master): master = _default_root self._master = master self._tk = master.tk if name: self._name = name else: self._name = ('PY_VAR' + repr(_varnum)) _varnum += 1 if (value is not None): self.set(value) elif (not self._tk.call(...
'Unset the variable in Tcl.'
def __del__(self):
self._tk.globalunsetvar(self._name)
'Return the name of the variable in Tcl.'
def __str__(self):
return self._name
'Set the variable to VALUE.'
def set(self, value):
return self._tk.globalsetvar(self._name, value)
'Return value of variable.'
def get(self):
return self._tk.globalgetvar(self._name)
'Define a trace callback for the variable. MODE is one of "r", "w", "u" for read, write, undefine. CALLBACK must be a function which is called when the variable is read, written or undefined. Return the name of the callback.'
def trace_variable(self, mode, callback):
cbname = self._master._register(callback) self._tk.call('trace', 'variable', self._name, mode, cbname) return cbname
'Delete the trace callback for a variable. MODE is one of "r", "w", "u" for read, write, undefine. CBNAME is the name of the callback returned from trace_variable or trace.'
def trace_vdelete(self, mode, cbname):
self._tk.call('trace', 'vdelete', self._name, mode, cbname) self._master.deletecommand(cbname)
'Return all trace callback information.'
def trace_vinfo(self):
return map(self._tk.split, self._tk.splitlist(self._tk.call('trace', 'vinfo', self._name)))
'Comparison for equality (==). Note: if the Variable\'s master matters to behavior also compare self._master == other._master'
def __eq__(self, other):
return ((self.__class__.__name__ == other.__class__.__name__) and (self._name == other._name))
'Construct a string variable. MASTER can be given as master widget. VALUE is an optional value (defaults to "") NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.'
def __init__(self, master=None, value=None, name=None):
Variable.__init__(self, master, value, name)
'Return value of variable as string.'
def get(self):
value = self._tk.globalgetvar(self._name) if isinstance(value, basestring): return value return str(value)
'Construct an integer variable. MASTER can be given as master widget. VALUE is an optional value (defaults to 0) NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.'
def __init__(self, master=None, value=None, name=None):
Variable.__init__(self, master, value, name)
'Set the variable to value, converting booleans to integers.'
def set(self, value):
if isinstance(value, bool): value = int(value) return Variable.set(self, value)
'Return the value of the variable as an integer.'
def get(self):
return getint(self._tk.globalgetvar(self._name))
'Construct a float variable. MASTER can be given as master widget. VALUE is an optional value (defaults to 0.0) NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.'
def __init__(self, master=None, value=None, name=None):
Variable.__init__(self, master, value, name)
'Return the value of the variable as a float.'
def get(self):
return getdouble(self._tk.globalgetvar(self._name))
'Construct a boolean variable. MASTER can be given as master widget. VALUE is an optional value (defaults to False) NAME is an optional Tcl name (defaults to PY_VARnum). If NAME matches an existing variable and VALUE is omitted then the existing value is retained.'
def __init__(self, master=None, value=None, name=None):
Variable.__init__(self, master, value, name)
'Return the value of the variable as a bool.'
def get(self):
return self._tk.getboolean(self._tk.globalgetvar(self._name))
'Internal function. Delete all Tcl commands created for this widget in the Tcl interpreter.'
def destroy(self):
if (self._tclCommands is not None): for name in self._tclCommands: self.tk.deletecommand(name) self._tclCommands = None
'Internal function. Delete the Tcl command provided in NAME.'
def deletecommand(self, name):
self.tk.deletecommand(name) try: self._tclCommands.remove(name) except ValueError: pass
'Set Tcl internal variable, whether the look and feel should adhere to Motif. A parameter of 1 means adhere to Motif (e.g. no color change if mouse passes over slider). Returns the set value.'
def tk_strictMotif(self, boolean=None):
return self.tk.getboolean(self.tk.call('set', 'tk_strictMotif', boolean))
'Change the color scheme to light brown as used in Tk 3.6 and before.'
def tk_bisque(self):
self.tk.call('tk_bisque')
'Set a new color scheme for all widget elements. A single color as argument will cause that all colors of Tk widget elements are derived from this. Alternatively several keyword parameters and its associated colors can be given. The following keywords are valid: activeBackground, foreground, selectColor, activeForegrou...
def tk_setPalette(self, *args, **kw):
self.tk.call(((('tk_setPalette',) + _flatten(args)) + _flatten(kw.items())))
'Do not use. Needed in Tk 3.6 and earlier.'
def tk_menuBar(self, *args):
pass
'Wait until the variable is modified. A parameter of type IntVar, StringVar, DoubleVar or BooleanVar must be given.'
def wait_variable(self, name='PY_VAR'):
self.tk.call('tkwait', 'variable', name)
'Wait until a WIDGET is destroyed. If no parameter is given self is used.'
def wait_window(self, window=None):
if (window is None): window = self self.tk.call('tkwait', 'window', window._w)
'Wait until the visibility of a WIDGET changes (e.g. it appears). If no parameter is given self is used.'
def wait_visibility(self, window=None):
if (window is None): window = self self.tk.call('tkwait', 'visibility', window._w)
'Set Tcl variable NAME to VALUE.'
def setvar(self, name='PY_VAR', value='1'):
self.tk.setvar(name, value)
'Return value of Tcl variable NAME.'
def getvar(self, name='PY_VAR'):
return self.tk.getvar(name)
'Return a boolean value for Tcl boolean values true and false given as parameter.'
def getboolean(self, s):
return self.tk.getboolean(s)
'Direct input focus to this widget. If the application currently does not have the focus this widget will get the focus if the application gets the focus through the window manager.'
def focus_set(self):
self.tk.call('focus', self._w)
'Direct input focus to this widget even if the application does not have the focus. Use with caution!'
def focus_force(self):
self.tk.call('focus', '-force', self._w)
'Return the widget which has currently the focus in the application. Use focus_displayof to allow working with several displays. Return None if application does not have the focus.'
def focus_get(self):
name = self.tk.call('focus') if ((name == 'none') or (not name)): return None return self._nametowidget(name)
'Return the widget which has currently the focus on the display where this widget is located. Return None if the application does not have the focus.'
def focus_displayof(self):
name = self.tk.call('focus', '-displayof', self._w) if ((name == 'none') or (not name)): return None return self._nametowidget(name)
'Return the widget which would have the focus if top level for this widget gets the focus from the window manager.'
def focus_lastfor(self):
name = self.tk.call('focus', '-lastfor', self._w) if ((name == 'none') or (not name)): return None return self._nametowidget(name)
'The widget under mouse will get automatically focus. Can not be disabled easily.'
def tk_focusFollowsMouse(self):
self.tk.call('tk_focusFollowsMouse')