MCPcopy Index your code
hub / github.com/python/cpython / onkey

Method onkey

Lib/turtle.py:1394–1422  ·  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

1392 self._onscreenclick(fun, btn, add)
1393
1394 def onkey(self, fun, key):
1395 """Bind fun to key-release event of key.
1396
1397 Arguments:
1398 fun -- a function with no arguments
1399 key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
1400
1401 In order to be able to register key-events, TurtleScreen
1402 must have focus. (See method listen.)
1403
1404 Example (for a TurtleScreen instance named screen):
1405
1406 >>> def f():
1407 ... fd(50)
1408 ... lt(60)
1409 ...
1410 >>> screen.onkey(f, "Up")
1411 >>> screen.listen()
1412
1413 Subsequently the turtle can be moved by repeatedly pressing
1414 the up-arrow key, consequently drawing a hexagon
1415
1416 """
1417 if fun is None:
1418 if key in self._keys:
1419 self._keys.remove(key)
1420 elif key not in self._keys:
1421 self._keys.append(key)
1422 self._onkeyrelease(fun, key)
1423
1424 def onkeypress(self, fun, key=None):
1425 """Bind fun to key-press event of key if key is given,

Callers 2

clearMethod · 0.95
__init__Method · 0.80

Calls 3

_onkeyreleaseMethod · 0.80
removeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected