MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / onkey

Method onkey

Python/Turtle.py:1265–1293  ·  view source on GitHub ↗

Bind fun to key-release event of key. Arguments: fun -- a function with no arguments key -- a string: key (e.g. "a") or key-symbol (e.g. "space") In order to be able to register key-events, TurtleScreen must have focus. (See method listen.) Example

(self, fun, key)

Source from the content-addressed store, hash-verified

1263 self._onscreenclick(fun, btn, add)
1264
1265 def onkey(self, fun, key):
1266 """Bind fun to key-release event of key.
1267
1268 Arguments:
1269 fun -- a function with no arguments
1270 key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
1271
1272 In order to be able to register key-events, TurtleScreen
1273 must have focus. (See method listen.)
1274
1275 Example (for a TurtleScreen instance named screen):
1276
1277 >>> def f():
1278 ... fd(50)
1279 ... lt(60)
1280 ...
1281 >>> screen.onkey(f, "Up")
1282 >>> screen.listen()
1283
1284 Subsequently the turtle can be moved by repeatedly pressing
1285 the up-arrow key, consequently drawing a hexagon
1286
1287 """
1288 if fun is None:
1289 if key in self._keys:
1290 self._keys.remove(key)
1291 elif key not in self._keys:
1292 self._keys.append(key)
1293 self._onkeyrelease(fun, key)
1294
1295 def onkeypress(self, fun, key=None):
1296 """Bind fun to key-press event of key if key is given,

Callers 1

clearMethod · 0.95

Calls 2

_onkeyreleaseMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected