Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: turtle.py
rootwindow = cv.winfo_toplevel()
[1000] Fix | Delete
rootwindow.call('wm', 'attributes', '.', '-topmost', '1')
[1001] Fix | Delete
rootwindow.call('wm', 'attributes', '.', '-topmost', '0')
[1002] Fix | Delete
[1003] Fix | Delete
def clear(self):
[1004] Fix | Delete
"""Delete all drawings and all turtles from the TurtleScreen.
[1005] Fix | Delete
[1006] Fix | Delete
No argument.
[1007] Fix | Delete
[1008] Fix | Delete
Reset empty TurtleScreen to its initial state: white background,
[1009] Fix | Delete
no backgroundimage, no eventbindings and tracing on.
[1010] Fix | Delete
[1011] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1012] Fix | Delete
>>> screen.clear()
[1013] Fix | Delete
[1014] Fix | Delete
Note: this method is not available as function.
[1015] Fix | Delete
"""
[1016] Fix | Delete
self._delayvalue = _CFG["delay"]
[1017] Fix | Delete
self._colormode = _CFG["colormode"]
[1018] Fix | Delete
self._delete("all")
[1019] Fix | Delete
self._bgpic = self._createimage("")
[1020] Fix | Delete
self._bgpicname = "nopic"
[1021] Fix | Delete
self._tracing = 1
[1022] Fix | Delete
self._updatecounter = 0
[1023] Fix | Delete
self._turtles = []
[1024] Fix | Delete
self.bgcolor("white")
[1025] Fix | Delete
for btn in 1, 2, 3:
[1026] Fix | Delete
self.onclick(None, btn)
[1027] Fix | Delete
self.onkeypress(None)
[1028] Fix | Delete
for key in self._keys[:]:
[1029] Fix | Delete
self.onkey(None, key)
[1030] Fix | Delete
self.onkeypress(None, key)
[1031] Fix | Delete
Turtle._pen = None
[1032] Fix | Delete
[1033] Fix | Delete
def mode(self, mode=None):
[1034] Fix | Delete
"""Set turtle-mode ('standard', 'logo' or 'world') and perform reset.
[1035] Fix | Delete
[1036] Fix | Delete
Optional argument:
[1037] Fix | Delete
mode -- one of the strings 'standard', 'logo' or 'world'
[1038] Fix | Delete
[1039] Fix | Delete
Mode 'standard' is compatible with turtle.py.
[1040] Fix | Delete
Mode 'logo' is compatible with most Logo-Turtle-Graphics.
[1041] Fix | Delete
Mode 'world' uses userdefined 'worldcoordinates'. *Attention*: in
[1042] Fix | Delete
this mode angles appear distorted if x/y unit-ratio doesn't equal 1.
[1043] Fix | Delete
If mode is not given, return the current mode.
[1044] Fix | Delete
[1045] Fix | Delete
Mode Initial turtle heading positive angles
[1046] Fix | Delete
------------|-------------------------|-------------------
[1047] Fix | Delete
'standard' to the right (east) counterclockwise
[1048] Fix | Delete
'logo' upward (north) clockwise
[1049] Fix | Delete
[1050] Fix | Delete
Examples:
[1051] Fix | Delete
>>> mode('logo') # resets turtle heading to north
[1052] Fix | Delete
>>> mode()
[1053] Fix | Delete
'logo'
[1054] Fix | Delete
"""
[1055] Fix | Delete
if mode is None:
[1056] Fix | Delete
return self._mode
[1057] Fix | Delete
mode = mode.lower()
[1058] Fix | Delete
if mode not in ["standard", "logo", "world"]:
[1059] Fix | Delete
raise TurtleGraphicsError("No turtle-graphics-mode %s" % mode)
[1060] Fix | Delete
self._mode = mode
[1061] Fix | Delete
if mode in ["standard", "logo"]:
[1062] Fix | Delete
self._setscrollregion(-self.canvwidth//2, -self.canvheight//2,
[1063] Fix | Delete
self.canvwidth//2, self.canvheight//2)
[1064] Fix | Delete
self.xscale = self.yscale = 1.0
[1065] Fix | Delete
self.reset()
[1066] Fix | Delete
[1067] Fix | Delete
def setworldcoordinates(self, llx, lly, urx, ury):
[1068] Fix | Delete
"""Set up a user defined coordinate-system.
[1069] Fix | Delete
[1070] Fix | Delete
Arguments:
[1071] Fix | Delete
llx -- a number, x-coordinate of lower left corner of canvas
[1072] Fix | Delete
lly -- a number, y-coordinate of lower left corner of canvas
[1073] Fix | Delete
urx -- a number, x-coordinate of upper right corner of canvas
[1074] Fix | Delete
ury -- a number, y-coordinate of upper right corner of canvas
[1075] Fix | Delete
[1076] Fix | Delete
Set up user coodinat-system and switch to mode 'world' if necessary.
[1077] Fix | Delete
This performs a screen.reset. If mode 'world' is already active,
[1078] Fix | Delete
all drawings are redrawn according to the new coordinates.
[1079] Fix | Delete
[1080] Fix | Delete
But ATTENTION: in user-defined coordinatesystems angles may appear
[1081] Fix | Delete
distorted. (see Screen.mode())
[1082] Fix | Delete
[1083] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1084] Fix | Delete
>>> screen.setworldcoordinates(-10,-0.5,50,1.5)
[1085] Fix | Delete
>>> for _ in range(36):
[1086] Fix | Delete
... left(10)
[1087] Fix | Delete
... forward(0.5)
[1088] Fix | Delete
"""
[1089] Fix | Delete
if self.mode() != "world":
[1090] Fix | Delete
self.mode("world")
[1091] Fix | Delete
xspan = float(urx - llx)
[1092] Fix | Delete
yspan = float(ury - lly)
[1093] Fix | Delete
wx, wy = self._window_size()
[1094] Fix | Delete
self.screensize(wx-20, wy-20)
[1095] Fix | Delete
oldxscale, oldyscale = self.xscale, self.yscale
[1096] Fix | Delete
self.xscale = self.canvwidth / xspan
[1097] Fix | Delete
self.yscale = self.canvheight / yspan
[1098] Fix | Delete
srx1 = llx * self.xscale
[1099] Fix | Delete
sry1 = -ury * self.yscale
[1100] Fix | Delete
srx2 = self.canvwidth + srx1
[1101] Fix | Delete
sry2 = self.canvheight + sry1
[1102] Fix | Delete
self._setscrollregion(srx1, sry1, srx2, sry2)
[1103] Fix | Delete
self._rescale(self.xscale/oldxscale, self.yscale/oldyscale)
[1104] Fix | Delete
self.update()
[1105] Fix | Delete
[1106] Fix | Delete
def register_shape(self, name, shape=None):
[1107] Fix | Delete
"""Adds a turtle shape to TurtleScreen's shapelist.
[1108] Fix | Delete
[1109] Fix | Delete
Arguments:
[1110] Fix | Delete
(1) name is the name of a gif-file and shape is None.
[1111] Fix | Delete
Installs the corresponding image shape.
[1112] Fix | Delete
!! Image-shapes DO NOT rotate when turning the turtle,
[1113] Fix | Delete
!! so they do not display the heading of the turtle!
[1114] Fix | Delete
(2) name is an arbitrary string and shape is a tuple
[1115] Fix | Delete
of pairs of coordinates. Installs the corresponding
[1116] Fix | Delete
polygon shape
[1117] Fix | Delete
(3) name is an arbitrary string and shape is a
[1118] Fix | Delete
(compound) Shape object. Installs the corresponding
[1119] Fix | Delete
compound shape.
[1120] Fix | Delete
To use a shape, you have to issue the command shape(shapename).
[1121] Fix | Delete
[1122] Fix | Delete
call: register_shape("turtle.gif")
[1123] Fix | Delete
--or: register_shape("tri", ((0,0), (10,10), (-10,10)))
[1124] Fix | Delete
[1125] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1126] Fix | Delete
>>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
[1127] Fix | Delete
[1128] Fix | Delete
"""
[1129] Fix | Delete
if shape is None:
[1130] Fix | Delete
# image
[1131] Fix | Delete
if name.lower().endswith(".gif"):
[1132] Fix | Delete
shape = Shape("image", self._image(name))
[1133] Fix | Delete
else:
[1134] Fix | Delete
raise TurtleGraphicsError("Bad arguments for register_shape.\n"
[1135] Fix | Delete
+ "Use help(register_shape)" )
[1136] Fix | Delete
elif isinstance(shape, tuple):
[1137] Fix | Delete
shape = Shape("polygon", shape)
[1138] Fix | Delete
## else shape assumed to be Shape-instance
[1139] Fix | Delete
self._shapes[name] = shape
[1140] Fix | Delete
[1141] Fix | Delete
def _colorstr(self, color):
[1142] Fix | Delete
"""Return color string corresponding to args.
[1143] Fix | Delete
[1144] Fix | Delete
Argument may be a string or a tuple of three
[1145] Fix | Delete
numbers corresponding to actual colormode,
[1146] Fix | Delete
i.e. in the range 0<=n<=colormode.
[1147] Fix | Delete
[1148] Fix | Delete
If the argument doesn't represent a color,
[1149] Fix | Delete
an error is raised.
[1150] Fix | Delete
"""
[1151] Fix | Delete
if len(color) == 1:
[1152] Fix | Delete
color = color[0]
[1153] Fix | Delete
if isinstance(color, str):
[1154] Fix | Delete
if self._iscolorstring(color) or color == "":
[1155] Fix | Delete
return color
[1156] Fix | Delete
else:
[1157] Fix | Delete
raise TurtleGraphicsError("bad color string: %s" % str(color))
[1158] Fix | Delete
try:
[1159] Fix | Delete
r, g, b = color
[1160] Fix | Delete
except (TypeError, ValueError):
[1161] Fix | Delete
raise TurtleGraphicsError("bad color arguments: %s" % str(color))
[1162] Fix | Delete
if self._colormode == 1.0:
[1163] Fix | Delete
r, g, b = [round(255.0*x) for x in (r, g, b)]
[1164] Fix | Delete
if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)):
[1165] Fix | Delete
raise TurtleGraphicsError("bad color sequence: %s" % str(color))
[1166] Fix | Delete
return "#%02x%02x%02x" % (r, g, b)
[1167] Fix | Delete
[1168] Fix | Delete
def _color(self, cstr):
[1169] Fix | Delete
if not cstr.startswith("#"):
[1170] Fix | Delete
return cstr
[1171] Fix | Delete
if len(cstr) == 7:
[1172] Fix | Delete
cl = [int(cstr[i:i+2], 16) for i in (1, 3, 5)]
[1173] Fix | Delete
elif len(cstr) == 4:
[1174] Fix | Delete
cl = [16*int(cstr[h], 16) for h in cstr[1:]]
[1175] Fix | Delete
else:
[1176] Fix | Delete
raise TurtleGraphicsError("bad colorstring: %s" % cstr)
[1177] Fix | Delete
return tuple(c * self._colormode/255 for c in cl)
[1178] Fix | Delete
[1179] Fix | Delete
def colormode(self, cmode=None):
[1180] Fix | Delete
"""Return the colormode or set it to 1.0 or 255.
[1181] Fix | Delete
[1182] Fix | Delete
Optional argument:
[1183] Fix | Delete
cmode -- one of the values 1.0 or 255
[1184] Fix | Delete
[1185] Fix | Delete
r, g, b values of colortriples have to be in range 0..cmode.
[1186] Fix | Delete
[1187] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1188] Fix | Delete
>>> screen.colormode()
[1189] Fix | Delete
1.0
[1190] Fix | Delete
>>> screen.colormode(255)
[1191] Fix | Delete
>>> pencolor(240,160,80)
[1192] Fix | Delete
"""
[1193] Fix | Delete
if cmode is None:
[1194] Fix | Delete
return self._colormode
[1195] Fix | Delete
if cmode == 1.0:
[1196] Fix | Delete
self._colormode = float(cmode)
[1197] Fix | Delete
elif cmode == 255:
[1198] Fix | Delete
self._colormode = int(cmode)
[1199] Fix | Delete
[1200] Fix | Delete
def reset(self):
[1201] Fix | Delete
"""Reset all Turtles on the Screen to their initial state.
[1202] Fix | Delete
[1203] Fix | Delete
No argument.
[1204] Fix | Delete
[1205] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1206] Fix | Delete
>>> screen.reset()
[1207] Fix | Delete
"""
[1208] Fix | Delete
for turtle in self._turtles:
[1209] Fix | Delete
turtle._setmode(self._mode)
[1210] Fix | Delete
turtle.reset()
[1211] Fix | Delete
[1212] Fix | Delete
def turtles(self):
[1213] Fix | Delete
"""Return the list of turtles on the screen.
[1214] Fix | Delete
[1215] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1216] Fix | Delete
>>> screen.turtles()
[1217] Fix | Delete
[<turtle.Turtle object at 0x00E11FB0>]
[1218] Fix | Delete
"""
[1219] Fix | Delete
return self._turtles
[1220] Fix | Delete
[1221] Fix | Delete
def bgcolor(self, *args):
[1222] Fix | Delete
"""Set or return backgroundcolor of the TurtleScreen.
[1223] Fix | Delete
[1224] Fix | Delete
Arguments (if given): a color string or three numbers
[1225] Fix | Delete
in the range 0..colormode or a 3-tuple of such numbers.
[1226] Fix | Delete
[1227] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1228] Fix | Delete
>>> screen.bgcolor("orange")
[1229] Fix | Delete
>>> screen.bgcolor()
[1230] Fix | Delete
'orange'
[1231] Fix | Delete
>>> screen.bgcolor(0.5,0,0.5)
[1232] Fix | Delete
>>> screen.bgcolor()
[1233] Fix | Delete
'#800080'
[1234] Fix | Delete
"""
[1235] Fix | Delete
if args:
[1236] Fix | Delete
color = self._colorstr(args)
[1237] Fix | Delete
else:
[1238] Fix | Delete
color = None
[1239] Fix | Delete
color = self._bgcolor(color)
[1240] Fix | Delete
if color is not None:
[1241] Fix | Delete
color = self._color(color)
[1242] Fix | Delete
return color
[1243] Fix | Delete
[1244] Fix | Delete
def tracer(self, n=None, delay=None):
[1245] Fix | Delete
"""Turns turtle animation on/off and set delay for update drawings.
[1246] Fix | Delete
[1247] Fix | Delete
Optional arguments:
[1248] Fix | Delete
n -- nonnegative integer
[1249] Fix | Delete
delay -- nonnegative integer
[1250] Fix | Delete
[1251] Fix | Delete
If n is given, only each n-th regular screen update is really performed.
[1252] Fix | Delete
(Can be used to accelerate the drawing of complex graphics.)
[1253] Fix | Delete
Second arguments sets delay value (see RawTurtle.delay())
[1254] Fix | Delete
[1255] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1256] Fix | Delete
>>> screen.tracer(8, 25)
[1257] Fix | Delete
>>> dist = 2
[1258] Fix | Delete
>>> for i in range(200):
[1259] Fix | Delete
... fd(dist)
[1260] Fix | Delete
... rt(90)
[1261] Fix | Delete
... dist += 2
[1262] Fix | Delete
"""
[1263] Fix | Delete
if n is None:
[1264] Fix | Delete
return self._tracing
[1265] Fix | Delete
self._tracing = int(n)
[1266] Fix | Delete
self._updatecounter = 0
[1267] Fix | Delete
if delay is not None:
[1268] Fix | Delete
self._delayvalue = int(delay)
[1269] Fix | Delete
if self._tracing:
[1270] Fix | Delete
self.update()
[1271] Fix | Delete
[1272] Fix | Delete
def delay(self, delay=None):
[1273] Fix | Delete
""" Return or set the drawing delay in milliseconds.
[1274] Fix | Delete
[1275] Fix | Delete
Optional argument:
[1276] Fix | Delete
delay -- positive integer
[1277] Fix | Delete
[1278] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1279] Fix | Delete
>>> screen.delay(15)
[1280] Fix | Delete
>>> screen.delay()
[1281] Fix | Delete
15
[1282] Fix | Delete
"""
[1283] Fix | Delete
if delay is None:
[1284] Fix | Delete
return self._delayvalue
[1285] Fix | Delete
self._delayvalue = int(delay)
[1286] Fix | Delete
[1287] Fix | Delete
def _incrementudc(self):
[1288] Fix | Delete
"""Increment update counter."""
[1289] Fix | Delete
if not TurtleScreen._RUNNING:
[1290] Fix | Delete
TurtleScreen._RUNNING = True
[1291] Fix | Delete
raise Terminator
[1292] Fix | Delete
if self._tracing > 0:
[1293] Fix | Delete
self._updatecounter += 1
[1294] Fix | Delete
self._updatecounter %= self._tracing
[1295] Fix | Delete
[1296] Fix | Delete
def update(self):
[1297] Fix | Delete
"""Perform a TurtleScreen update.
[1298] Fix | Delete
"""
[1299] Fix | Delete
tracing = self._tracing
[1300] Fix | Delete
self._tracing = True
[1301] Fix | Delete
for t in self.turtles():
[1302] Fix | Delete
t._update_data()
[1303] Fix | Delete
t._drawturtle()
[1304] Fix | Delete
self._tracing = tracing
[1305] Fix | Delete
self._update()
[1306] Fix | Delete
[1307] Fix | Delete
def window_width(self):
[1308] Fix | Delete
""" Return the width of the turtle window.
[1309] Fix | Delete
[1310] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1311] Fix | Delete
>>> screen.window_width()
[1312] Fix | Delete
640
[1313] Fix | Delete
"""
[1314] Fix | Delete
return self._window_size()[0]
[1315] Fix | Delete
[1316] Fix | Delete
def window_height(self):
[1317] Fix | Delete
""" Return the height of the turtle window.
[1318] Fix | Delete
[1319] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1320] Fix | Delete
>>> screen.window_height()
[1321] Fix | Delete
480
[1322] Fix | Delete
"""
[1323] Fix | Delete
return self._window_size()[1]
[1324] Fix | Delete
[1325] Fix | Delete
def getcanvas(self):
[1326] Fix | Delete
"""Return the Canvas of this TurtleScreen.
[1327] Fix | Delete
[1328] Fix | Delete
No argument.
[1329] Fix | Delete
[1330] Fix | Delete
Example (for a Screen instance named screen):
[1331] Fix | Delete
>>> cv = screen.getcanvas()
[1332] Fix | Delete
>>> cv
[1333] Fix | Delete
<turtle.ScrolledCanvas instance at 0x010742D8>
[1334] Fix | Delete
"""
[1335] Fix | Delete
return self.cv
[1336] Fix | Delete
[1337] Fix | Delete
def getshapes(self):
[1338] Fix | Delete
"""Return a list of names of all currently available turtle shapes.
[1339] Fix | Delete
[1340] Fix | Delete
No argument.
[1341] Fix | Delete
[1342] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1343] Fix | Delete
>>> screen.getshapes()
[1344] Fix | Delete
['arrow', 'blank', 'circle', ... , 'turtle']
[1345] Fix | Delete
"""
[1346] Fix | Delete
return sorted(self._shapes.keys())
[1347] Fix | Delete
[1348] Fix | Delete
def onclick(self, fun, btn=1, add=None):
[1349] Fix | Delete
"""Bind fun to mouse-click event on canvas.
[1350] Fix | Delete
[1351] Fix | Delete
Arguments:
[1352] Fix | Delete
fun -- a function with two arguments, the coordinates of the
[1353] Fix | Delete
clicked point on the canvas.
[1354] Fix | Delete
btn -- the number of the mouse-button, defaults to 1
[1355] Fix | Delete
[1356] Fix | Delete
Example (for a TurtleScreen instance named screen)
[1357] Fix | Delete
[1358] Fix | Delete
>>> screen.onclick(goto)
[1359] Fix | Delete
>>> # Subsequently clicking into the TurtleScreen will
[1360] Fix | Delete
>>> # make the turtle move to the clicked point.
[1361] Fix | Delete
>>> screen.onclick(None)
[1362] Fix | Delete
"""
[1363] Fix | Delete
self._onscreenclick(fun, btn, add)
[1364] Fix | Delete
[1365] Fix | Delete
def onkey(self, fun, key):
[1366] Fix | Delete
"""Bind fun to key-release event of key.
[1367] Fix | Delete
[1368] Fix | Delete
Arguments:
[1369] Fix | Delete
fun -- a function with no arguments
[1370] Fix | Delete
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
[1371] Fix | Delete
[1372] Fix | Delete
In order to be able to register key-events, TurtleScreen
[1373] Fix | Delete
must have focus. (See method listen.)
[1374] Fix | Delete
[1375] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1376] Fix | Delete
[1377] Fix | Delete
>>> def f():
[1378] Fix | Delete
... fd(50)
[1379] Fix | Delete
... lt(60)
[1380] Fix | Delete
...
[1381] Fix | Delete
>>> screen.onkey(f, "Up")
[1382] Fix | Delete
>>> screen.listen()
[1383] Fix | Delete
[1384] Fix | Delete
Subsequently the turtle can be moved by repeatedly pressing
[1385] Fix | Delete
the up-arrow key, consequently drawing a hexagon
[1386] Fix | Delete
[1387] Fix | Delete
"""
[1388] Fix | Delete
if fun is None:
[1389] Fix | Delete
if key in self._keys:
[1390] Fix | Delete
self._keys.remove(key)
[1391] Fix | Delete
elif key not in self._keys:
[1392] Fix | Delete
self._keys.append(key)
[1393] Fix | Delete
self._onkeyrelease(fun, key)
[1394] Fix | Delete
[1395] Fix | Delete
def onkeypress(self, fun, key=None):
[1396] Fix | Delete
"""Bind fun to key-press event of key if key is given,
[1397] Fix | Delete
or to any key-press-event if no key is given.
[1398] Fix | Delete
[1399] Fix | Delete
Arguments:
[1400] Fix | Delete
fun -- a function with no arguments
[1401] Fix | Delete
key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
[1402] Fix | Delete
[1403] Fix | Delete
In order to be able to register key-events, TurtleScreen
[1404] Fix | Delete
must have focus. (See method listen.)
[1405] Fix | Delete
[1406] Fix | Delete
Example (for a TurtleScreen instance named screen
[1407] Fix | Delete
and a Turtle instance named turtle):
[1408] Fix | Delete
[1409] Fix | Delete
>>> def f():
[1410] Fix | Delete
... fd(50)
[1411] Fix | Delete
... lt(60)
[1412] Fix | Delete
...
[1413] Fix | Delete
>>> screen.onkeypress(f, "Up")
[1414] Fix | Delete
>>> screen.listen()
[1415] Fix | Delete
[1416] Fix | Delete
Subsequently the turtle can be moved by repeatedly pressing
[1417] Fix | Delete
the up-arrow key, or by keeping pressed the up-arrow key.
[1418] Fix | Delete
consequently drawing a hexagon.
[1419] Fix | Delete
"""
[1420] Fix | Delete
if fun is None:
[1421] Fix | Delete
if key in self._keys:
[1422] Fix | Delete
self._keys.remove(key)
[1423] Fix | Delete
elif key is not None and key not in self._keys:
[1424] Fix | Delete
self._keys.append(key)
[1425] Fix | Delete
self._onkeypress(fun, key)
[1426] Fix | Delete
[1427] Fix | Delete
def listen(self, xdummy=None, ydummy=None):
[1428] Fix | Delete
"""Set focus on TurtleScreen (in order to collect key-events)
[1429] Fix | Delete
[1430] Fix | Delete
No arguments.
[1431] Fix | Delete
Dummy arguments are provided in order
[1432] Fix | Delete
to be able to pass listen to the onclick method.
[1433] Fix | Delete
[1434] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1435] Fix | Delete
>>> screen.listen()
[1436] Fix | Delete
"""
[1437] Fix | Delete
self._listen()
[1438] Fix | Delete
[1439] Fix | Delete
def ontimer(self, fun, t=0):
[1440] Fix | Delete
"""Install a timer, which calls fun after t milliseconds.
[1441] Fix | Delete
[1442] Fix | Delete
Arguments:
[1443] Fix | Delete
fun -- a function with no arguments.
[1444] Fix | Delete
t -- a number >= 0
[1445] Fix | Delete
[1446] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1447] Fix | Delete
[1448] Fix | Delete
>>> running = True
[1449] Fix | Delete
>>> def f():
[1450] Fix | Delete
... if running:
[1451] Fix | Delete
... fd(50)
[1452] Fix | Delete
... lt(60)
[1453] Fix | Delete
... screen.ontimer(f, 250)
[1454] Fix | Delete
...
[1455] Fix | Delete
>>> f() # makes the turtle marching around
[1456] Fix | Delete
>>> running = False
[1457] Fix | Delete
"""
[1458] Fix | Delete
self._ontimer(fun, t)
[1459] Fix | Delete
[1460] Fix | Delete
def bgpic(self, picname=None):
[1461] Fix | Delete
"""Set background image or return name of current backgroundimage.
[1462] Fix | Delete
[1463] Fix | Delete
Optional argument:
[1464] Fix | Delete
picname -- a string, name of a gif-file or "nopic".
[1465] Fix | Delete
[1466] Fix | Delete
If picname is a filename, set the corresponding image as background.
[1467] Fix | Delete
If picname is "nopic", delete backgroundimage, if present.
[1468] Fix | Delete
If picname is None, return the filename of the current backgroundimage.
[1469] Fix | Delete
[1470] Fix | Delete
Example (for a TurtleScreen instance named screen):
[1471] Fix | Delete
>>> screen.bgpic()
[1472] Fix | Delete
'nopic'
[1473] Fix | Delete
>>> screen.bgpic("landscape.gif")
[1474] Fix | Delete
>>> screen.bgpic()
[1475] Fix | Delete
'landscape.gif'
[1476] Fix | Delete
"""
[1477] Fix | Delete
if picname is None:
[1478] Fix | Delete
return self._bgpicname
[1479] Fix | Delete
if picname not in self._bgpics:
[1480] Fix | Delete
self._bgpics[picname] = self._image(picname)
[1481] Fix | Delete
self._setbgpic(self._bgpic, self._bgpics[picname])
[1482] Fix | Delete
self._bgpicname = picname
[1483] Fix | Delete
[1484] Fix | Delete
def screensize(self, canvwidth=None, canvheight=None, bg=None):
[1485] Fix | Delete
"""Resize the canvas the turtles are drawing on.
[1486] Fix | Delete
[1487] Fix | Delete
Optional arguments:
[1488] Fix | Delete
canvwidth -- positive integer, new width of canvas in pixels
[1489] Fix | Delete
canvheight -- positive integer, new height of canvas in pixels
[1490] Fix | Delete
bg -- colorstring or color-tuple, new backgroundcolor
[1491] Fix | Delete
If no arguments are given, return current (canvaswidth, canvasheight)
[1492] Fix | Delete
[1493] Fix | Delete
Do not alter the drawing window. To observe hidden parts of
[1494] Fix | Delete
the canvas use the scrollbars. (Can make visible those parts
[1495] Fix | Delete
of a drawing, which were outside the canvas before!)
[1496] Fix | Delete
[1497] Fix | Delete
Example (for a Turtle instance named turtle):
[1498] Fix | Delete
>>> turtle.screensize(2000,1500)
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function