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: distance(vec) # e.g. as returned by pos() --or: distance(mypen) # where mypen is another turtle Return the angle, between the line from turtle-position to position specified by x, y and the turtle\'s start orientation. (Depends on modes - "standard" or "logo") Example (for a Turtle instance named turtle): >>> turtle.pos() (10.00, 10.00) >>> turtle.towards(0,0) 225.0'
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) result /= self._degreesPerAU return ((self._angleOffset + (self._angleOrient * result)) % self._fullcircle)
'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 - east 180 - west 180 - south 270 - south 270 - west Example (for a Turtle instance named turtle): >>> turtle.setheading(90) >>> turtle.heading() 90'
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. If extent is not a full circle, one endpoint of the arc is the current pen position. Draw the arc in counterclockwise direction if radius is positive, otherwise in clockwise direction. Finally the direction of the turtle is changed by the amount of extent. As the circle is approximated by an inscribed regular polygon, steps determines the number of steps to use. If not given, it will be calculated automatically. Maybe used to draw regular polygons. call: circle(radius) # full circle --or: circle(radius, extent) # arc --or: circle(radius, extent, steps) --or: circle(radius, steps=6) # 6-sided polygon Example (for a Turtle instance named turtle): >>> turtle.circle(50) >>> turtle.circle(120, 180) # semicircle'
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) * frac))) w = ((1.0 * extent) / steps) w2 = (0.5 * w) l = ((2.0 * radius) * math.sin((((w2 * math.pi) / 180.0) * self._degreesPerAU))) if (radius < 0): (l, w, w2) = ((- l), (- w), (- w2)) tr = self.tracer() dl = self._delay() if (speed == 0): self.tracer(0, 0) else: self.speed(0) self._rotate(w2) for i in range(steps): self.speed(speed) self._go(l) self.speed(0) self._rotate(w) self._rotate((- w2)) if (speed == 0): self.tracer(tr, dl) self.speed(speed) if self.undobuffer: self.undobuffer.cumulate = False
'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 according to the values of stretchfactor and outlinewidth (outline), which are set by shapesize() - "noresize" no adaption of the turtle\'s appearance takes place. If no argument is given, return current resizemode. resizemode("user") is called by a call of shapesize with arguments. Examples (for a Turtle instance named turtle): >>> turtle.resizemode("noresize") >>> turtle.resizemode() \'noresize\''
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 (for a Turtle instance named turtle): >>> turtle.pensize() 1 turtle.pensize(10) # from here on lines of width 10 are drawn'
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. Speedstrings are mapped to speedvalues in the following way: \'fastest\' : 0 \'fast\' : 10 \'normal\' : 6 \'slow\' : 3 \'slowest\' : 1 speeds from 1 to 10 enforce increasingly faster animation of line drawing and turtle turning. Attention: speed = 0 : *no* animation takes place. forward/back makes turtle jump and likewise left/right make the turtle turn instantly. Example (for a Turtle instance named turtle): >>> turtle.speed(3)'
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)), color(r,g,b) inputs as in pencolor, set both, fillcolor and pencolor, to the given value. color(colorstring1, colorstring2), color((r1,g1,b1), (r2,g2,b2)) equivalent to pencolor(colorstring1) and fillcolor(colorstring2) and analogously, if the other input format is used. If turtleshape is a polygon, outline and interior of that polygon is drawn with the newly set colors. For mor info see: pencolor, fillcolor Example (for a Turtle instance named turtle): >>> turtle.color(\'red\', \'green\') >>> turtle.color() (\'red\', \'green\') >>> colormode(255) >>> color((40, 80, 120), (160, 200, 240)) >>> color() (\'#285078\', \'#a0c8f0\')'
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=pcolor, fillcolor=fcolor) else: return (self._color(self._pencolor), self._color(self._fillcolor))
'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 as "red" or "yellow" - pencolor((r, g, b)) *a tuple* of r, g, and b, which represent, an RGB color, and each of r, g, and b are in the range 0..colormode, where colormode is either 1.0 or 255 - pencolor(r, g, b) r, g, and b represent an RGB color, and each of r, g, and b are in the range 0..colormode If turtleshape is a polygon, the outline of that polygon is drawn with the newly set pencolor. Example (for a Turtle instance named turtle): >>> turtle.pencolor(\'brown\') >>> tup = (0.2, 0.8, 0.55) >>> turtle.pencolor(tup) >>> turtle.pencolor() \'#33cc8c\''
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, such as "red" or "yellow" - fillcolor((r, g, b)) *a tuple* of r, g, and b, which represent, an RGB color, and each of r, g, and b are in the range 0..colormode, where colormode is either 1.0 or 255 - fillcolor(r, g, b) r, g, and b represent an RGB color, and each of r, g, and b are in the range 0..colormode If turtleshape is a polygon, the interior of that polygon is drawn with the newly set fillcolor. Example (for a Turtle instance named turtle): >>> turtle.fillcolor(\'violet\') >>> col = turtle.pencolor() >>> turtle.fillcolor(col) >>> turtle.fillcolor(0, .5, 0)'
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 "pendown" : True/False "pencolor" : color-string or color-tuple "fillcolor" : color-string or color-tuple "pensize" : positive number "speed" : number in range 0..10 "resizemode" : "auto" or "user" or "noresize" "stretchfactor": (positive number, positive number) "outline" : positive number "tilt" : number This dictionary can be used as argument for a subsequent pen()-call to restore the former pen-state. Moreover one or more of these attributes can be provided as keyword-arguments. This can be used to set several pen attributes in one statement. Examples (for a Turtle instance named turtle): >>> turtle.pen(fillcolor="black", pencolor="red", pensize=10) >>> turtle.pen() {\'pensize\': 10, \'shown\': True, \'resizemode\': \'auto\', \'outline\': 1, \'pencolor\': \'red\', \'pendown\': True, \'fillcolor\': \'black\', \'stretchfactor\': (1,1), \'speed\': 3} >>> penstate=turtle.pen() >>> turtle.color("yellow","") >>> turtle.penup() >>> turtle.pen() {\'pensize\': 10, \'shown\': True, \'resizemode\': \'auto\', \'outline\': 1, \'pencolor\': \'yellow\', \'pendown\': False, \'fillcolor\': \'\', \'stretchfactor\': (1,1), \'speed\': 3} >>> p.pen(penstate, fillcolor="green") >>> p.pen() {\'pensize\': 10, \'shown\': True, \'resizemode\': \'auto\', \'outline\': 1, \'pencolor\': \'red\', \'pendown\': True, \'fillcolor\': \'green\', \'stretchfactor\': (1,1), \'speed\': 3}'
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)): return _pd if isinstance(pen, dict): p = pen else: p = {} p.update(pendict) _p_buf = {} for key in p: _p_buf[key] = _pd[key] if self.undobuffer: self.undobuffer.push(('pen', _p_buf)) newLine = False if ('pendown' in p): if (self._drawing != p['pendown']): newLine = True if ('pencolor' in p): if isinstance(p['pencolor'], tuple): p['pencolor'] = self._colorstr((p['pencolor'],)) if (self._pencolor != p['pencolor']): newLine = True if ('pensize' in p): if (self._pensize != p['pensize']): newLine = True if newLine: self._newLine() if ('pendown' in p): self._drawing = p['pendown'] if ('pencolor' in p): self._pencolor = p['pencolor'] if ('pensize' in p): self._pensize = p['pensize'] if ('fillcolor' in p): if isinstance(p['fillcolor'], tuple): p['fillcolor'] = self._colorstr((p['fillcolor'],)) self._fillcolor = p['fillcolor'] if ('speed' in p): self._speed = p['speed'] if ('resizemode' in p): self._resizemode = p['resizemode'] if ('stretchfactor' in p): sf = p['stretchfactor'] if isinstance(sf, (int, float)): sf = (sf, sf) self._stretchfactor = sf if ('outline' in p): self._outlinewidth = p['outline'] if ('shown' in p): self._shown = p['shown'] if ('tilt' in p): self._tilt = p['tilt'] self._update()
'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() >>> turtle.position() (0.00,0.00) >>> turtle.heading() 0.0'
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): >>> turtle.setundobuffer(42)'
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() self.setundobuffer(self._undobuffersize)
'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 t in screen.turtles(): t._drawturtle() screen._update()
'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 Turtle instance named turtle): >>> turtle.tracer(8, 25) >>> dist = 2 >>> for i in range(200): turtle.fd(dist) turtle.rt(90) dist += 2'
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 <= 255) and (0 <= b <= 255))): raise TurtleGraphicsError(('bad color sequence: %s' % str(args))) return ('#%02x%02x%02x' % (r, g, b))
'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) ttype = screen._shapes[self.turtle.shapeIndex]._type if (ttype == 'polygon'): q.turtle._item = screen._createpoly() elif (ttype == 'image'): q.turtle._item = screen._createimage(screen._shapes['blank']._data) elif (ttype == 'compound'): q.turtle._item = [screen._createpoly() for item in screen._shapes[self.turtle.shapeIndex]._data] q.currentLineItem = screen._createline() q._update() return q
'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 the following polygon shapes: \'arrow\', \'turtle\', \'circle\', \'square\', \'triangle\', \'classic\'. To learn about how to deal with shapes see Screen-method register_shape. Example (for a Turtle instance named turtle): >>> turtle.shape() \'arrow\' >>> turtle.shape("turtle") >>> turtle.shape() \'turtle\''
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", the turtle will be displayed stretched according to its stretchfactors: stretch_wid is stretchfactor perpendicular to orientation stretch_len is stretchfactor in direction of turtles orientation. outline determines the width of the shapes\'s outline. Examples (for a Turtle instance named turtle): >>> turtle.resizemode("user") >>> turtle.shapesize(5, 5, 12) >>> turtle.shapesize(outline=8)'
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: stretchfactor = (stretch_wid, stretch_len) elif (stretch_len is not None): stretchfactor = (self._stretchfactor[0], stretch_len) else: stretchfactor = self._stretchfactor if (outline is None): outline = self._outlinewidth self.pen(resizemode='user', stretchfactor=stretchfactor, outline=outline)
'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.shape("circle") >>> turtle.shapesize(5,2) >>> turtle.settiltangle(45) >>> stamp() >>> turtle.fd(50) >>> turtle.settiltangle(-45) >>> stamp() >>> turtle.fd(50)'
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) >>> turtle.tiltangle()'
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(50) >>> turtle.tilt(30) >>> turtle.fd(50)'
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'): if (self._resizemode == 'noresize'): w = 1 shape = tshape else: if (self._resizemode == 'auto'): lx = ly = max(1, (self._pensize / 5.0)) w = self._pensize tiltangle = 0 elif (self._resizemode == 'user'): (lx, ly) = self._stretchfactor w = self._outlinewidth tiltangle = self._tilt shape = [((lx * x), (ly * y)) for (x, y) in tshape] (t0, t1) = (math.sin(tiltangle), math.cos(tiltangle)) shape = [(((t1 * x) + (t0 * y)), (((- t0) * x) + (t1 * y))) for (x, y) in shape] shape = self._polytrafo(shape) (fc, oc) = (self._fillcolor, self._pencolor) screen._drawpoly(titem, shape, fill=fc, outline=oc, width=w, top=True) elif (ttype == 'image'): screen._drawimage(titem, self._position, tshape) elif (ttype == 'compound'): (lx, ly) = self._stretchfactor w = self._outlinewidth for (item, (poly, fc, oc)) in zip(titem, tshape): poly = [((lx * x), (ly * y)) for (x, y) in poly] poly = self._polytrafo(poly) screen._drawpoly(item, poly, fill=self._cc(fc), outline=self._cc(oc), width=w, top=True) else: if self._hidden_from_screen: return if (ttype == 'polygon'): screen._drawpoly(titem, ((0, 0), (0, 0), (0, 0)), '', '') elif (ttype == 'image'): screen._drawimage(titem, self._position, screen._shapes['blank']._data) elif (ttype == 'compound'): for item in titem: screen._drawpoly(item, ((0, 0), (0, 0), (0, 0)), '', '') self._hidden_from_screen = True
'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.color("blue") >>> turtle.stamp() 13 >>> turtle.fd(50)'
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._resizemode == 'auto'): lx = ly = max(1, (self._pensize / 5.0)) w = self._pensize tiltangle = 0 elif (self._resizemode == 'user'): (lx, ly) = self._stretchfactor w = self._outlinewidth tiltangle = self._tilt shape = [((lx * x), (ly * y)) for (x, y) in tshape] (t0, t1) = (math.sin(tiltangle), math.cos(tiltangle)) shape = [(((t1 * x) + (t0 * y)), (((- t0) * x) + (t1 * y))) for (x, y) in shape] shape = self._polytrafo(shape) (fc, oc) = (self._fillcolor, self._pencolor) screen._drawpoly(stitem, shape, fill=fc, outline=oc, width=w, top=True) elif (ttype == 'image'): stitem = screen._createimage('') screen._drawimage(stitem, self._position, tshape) elif (ttype == 'compound'): stitem = [] for element in tshape: item = screen._createpoly() stitem.append(item) stitem = tuple(stitem) (lx, ly) = self._stretchfactor w = self._outlinewidth for (item, (poly, fc, oc)) in zip(stitem, tshape): poly = [((lx * x), (ly * y)) for (x, y) in poly] poly = self._polytrafo(poly) screen._drawpoly(item, poly, fill=self._cc(fc), outline=self._cc(oc), width=w, top=True) self.stampItems.append(stitem) self.undobuffer.push(('stamp', stitem)) return stitem
'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 not in buf.buffer): return index = buf.buffer.index(item) buf.buffer.remove(item) if (index <= buf.ptr): buf.ptr = ((buf.ptr - 1) % buf.bufsize) buf.buffer.insert(((buf.ptr + 1) % buf.bufsize), [None])
'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(2) >>> turtle.clearstamps(-2) >>> 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.undobuffer.push(undo_entry) start = self._position if (self._speed and (screen._tracing == 1)): diff = (end - start) diffsq = (((diff[0] * screen.xscale) ** 2) + ((diff[1] * screen.yscale) ** 2)) nhops = (1 + int(((diffsq ** 0.5) / ((3 * (1.1 ** self._speed)) * self._speed)))) delta = (diff * (1.0 / nhops)) for n in range(1, nhops): if (n == 1): top = True else: top = False self._position = (start + (delta * n)) if self._drawing: screen._drawline(self.drawingLineItem, (start, self._position), self._pencolor, self._pensize, top) self._update() if self._drawing: screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)), fill='', width=self._pensize) if self._drawing: self.currentLine.append(end) if isinstance(self._fillpath, list): self._fillpath.append(end) self._position = end if self._creatingPoly: self._poly.append(end) if (len(self.currentLine) > 42): self._newLine() self._update()
'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, 0), (0, 0)]): usepc = '' else: usepc = pc screen._drawline(cLI, pl, fill=usepc, width=ps) todelete = [i for i in self.items if ((i not in items) and (screen._type(i) == 'line'))] for i in todelete: screen._delete(i) self.items.remove(i) start = old if (self._speed and (screen._tracing == 1)): diff = (old - new) diffsq = (((diff[0] * screen.xscale) ** 2) + ((diff[1] * screen.yscale) ** 2)) nhops = (1 + int(((diffsq ** 0.5) / ((3 * (1.1 ** self._speed)) * self._speed)))) delta = (diff * (1.0 / nhops)) for n in range(1, nhops): if (n == 1): top = True else: top = False self._position = (new + (delta * n)) if drawing: screen._drawline(self.drawingLineItem, (start, self._position), pc, ps, top) self._update() if drawing: screen._drawline(self.drawingLineItem, ((0, 0), (0, 0)), fill='', width=ps) self._position = old if self._creatingPoly: if (len(self._poly) > 0): self._poly.pop() if (self._poly == []): self._creatingPoly = False self._poly = None if filling: if (self._fillpath == []): self._fillpath = None print 'Unwahrscheinlich in _undogoto!' elif (self._fillpath is not None): self._fillpath.pop() self._update()
'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) / anglevel))) delta = ((1.0 * angle) / steps) for _ in range(steps): self._orient = self._orient.rotate(delta) self._update() self._orient = neworient self._update()
'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) self.currentLine = [] if usePos: self.currentLine = [self._position]
'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 instance named turtle): >>> turtle.fill(True) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.left(90) >>> turtle.forward(100) >>> turtle.fill(False)'
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', self._fillitem) if flag: self._fillitem = self.screen._createpoly() self.items.append(self._fillitem) self._fillpath = [self._position] entry2 = ('beginfill', self._fillitem) self._newLine() else: self._fillitem = self._fillpath = None if self.undobuffer: if (entry1 == ()): if (entry2 != ()): self.undobuffer.push(entry2) elif (entry2 == ()): self.undobuffer.push(entry1) else: self.undobuffer.push(['seq', entry1, entry2]) self._update()
'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): >>> turtle.dot() >>> turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50)'
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: if (size is None): size = (self._pensize + max(self._pensize, 4)) color = self._colorstr(color) if hasattr(self.screen, '_dot'): item = self.screen._dot(self._position, size, color) self.items.append(item) if self.undobuffer: self.undobuffer.push(('dot', item)) else: pen = self.pen() if self.undobuffer: self.undobuffer.push(['seq']) self.undobuffer.cumulate = True try: if (self.resizemode() == 'auto'): self.ht() self.pendown() self.pensize(size) self.pencolor(color) self.forward(0) finally: self.pen(pen) if self.undobuffer: self.undobuffer.cumulate = False
'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 current turtle position according to align ("left", "center" or right") and with the given font. If move is True, the pen is moved to the bottom-right corner of the text. By default, move is False. Example (for a Turtle instance named turtle): >>> turtle.write(\'Home = \', True, align="center") >>> turtle.write((0,0), True)'
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.bgcolor("pink")'
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, otherwise it will replace a former binding. Example for the anonymous turtle, i. e. the procedural way: >>> def turn(x, y): left(360) >>> onclick(turn) # Now clicking into the turtle will turn it. >>> onclick(None) # event-binding will be removed'
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 MyTurtle(Turtle): def glow(self,x,y): self.fillcolor("red") def unglow(self,x,y): self.fillcolor("") >>> joe = MyTurtle() >>> joe.onclick(joe.glow) >>> joe.onrelease(joe.unglow) ### clicking on joe turns fillcolor red, ### unclicking turns it to transparent.'
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 mouse-click event on that turtle. Example (for a Turtle instance named turtle): >>> turtle.ondrag(turtle.goto) ### Subsequently clicking and dragging a Turtle will ### move it across the screen thereby producing handdrawings ### (if pen is down).'
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'): self._undogoto(data) elif (action in ['wri', 'dot']): item = data[0] self.screen._delete(item) self.items.remove(item) elif (action == 'dofill'): item = data[0] self.screen._drawpoly(item, ((0, 0), (0, 0), (0, 0)), fill='', outline='') elif (action == 'beginfill'): item = data[0] self._fillitem = self._fillpath = None self.screen._delete(item) self.items.remove(item) elif (action == 'pen'): TPen.pen(self, data[0]) self.undobuffer.pop()
'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 edge of the screen, if negative from the right edge Default, startx=None is to center window horizontally. starty: if positive, starting position in pixels from the top edge of the screen, if negative from the bottom edge Default, starty=None is to center window vertically. Examples (for a Screen instance named screen): >>> screen.setup (width=200, height=200, startx=0, starty=0) sets window to 200x200 pixels, in upper left of screen >>> screen.setup(width=.75, height=0.5, startx=None, starty=None) sets window to 75% of screen by 50% of screen and centers'
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 <= height <= 1)): height = (sh * height) if (starty is None): starty = ((sh - height) / 2) self._root.set_geometry(width, height, startx, starty) self.update()
'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 mainloop is active also for the client script. This is a method of the Screen-class and not available for TurtleScreen instances. Example (for a Screen instance named screen): >>> screen.exitonclick()'
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('info', 'exists', self._name)): self.set(self._default)
'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, activeForeground, highlightBackground, selectBackground, background, highlightColor, selectForeground, disabledForeground, insertBackground, troughColor.'
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')