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

Method _onkeypress

Python/Turtle.py:586–602  ·  view source on GitHub ↗

If key is given, bind fun to key-press event of key. Otherwise bind fun to any key-press. Canvas must have focus. See method listen.

(self, fun, key=None)

Source from the content-addressed store, hash-verified

584 self.cv.bind("<KeyRelease-%s>" % key, eventfun)
585
586 def _onkeypress(self, fun, key=None):
587 """If key is given, bind fun to key-press event of key.
588 Otherwise bind fun to any key-press.
589 Canvas must have focus. See method listen.
590 """
591 if fun is None:
592 if key is None:
593 self.cv.unbind("<KeyPress>", None)
594 else:
595 self.cv.unbind("<KeyPress-%s>" % key, None)
596 else:
597 def eventfun(event):
598 fun()
599 if key is None:
600 self.cv.bind("<KeyPress>", eventfun)
601 else:
602 self.cv.bind("<KeyPress-%s>" % key, eventfun)
603
604 def _listen(self):
605 """Set focus on canvas (in order to collect key-events)

Callers 1

onkeypressMethod · 0.80

Calls 2

unbindMethod · 0.80
bindMethod · 0.80

Tested by

no test coverage detected