MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / onkey

Method onkey

tools/python-3.11.9-amd64/Lib/turtle.py:1367–1395  ·  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.)

(self, fun, key)

Source from the content-addressed store, hash-verified

1365 self._onscreenclick(fun, btn, add)
1366
1367 def onkey(self, fun, key):
1368 """Bind fun to key-release event of key.
1369
1370 Arguments:
1371 fun -- a function with no arguments
1372 key -- a string: key (e.g. "a") or key-symbol (e.g. "space")
1373
1374 In order to be able to register key-events, TurtleScreen
1375 must have focus. (See method listen.)
1376
1377 Example (for a TurtleScreen instance named screen):
1378
1379 >>> def f():
1380 ... fd(50)
1381 ... lt(60)
1382 ...
1383 >>> screen.onkey(f, "Up")
1384 >>> screen.listen()
1385
1386 Subsequently the turtle can be moved by repeatedly pressing
1387 the up-arrow key, consequently drawing a hexagon
1388
1389 """
1390 if fun is None:
1391 if key in self._keys:
1392 self._keys.remove(key)
1393 elif key not in self._keys:
1394 self._keys.append(key)
1395 self._onkeyrelease(fun, key)
1396
1397 def onkeypress(self, fun, key=None):
1398 """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