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

Method _onkeypress

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

679 self.cv.bind("<KeyRelease-%s>" % key, eventfun)
680
681 def _onkeypress(self, fun, key=None):
682 """If key is given, bind fun to key-press event of key.
683 Otherwise bind fun to any key-press.
684 Canvas must have focus. See method listen.
685 """
686 if fun is None:
687 if key is None:
688 self.cv.unbind("<KeyPress>", None)
689 else:
690 self.cv.unbind("<KeyPress-%s>" % key, None)
691 else:
692 def eventfun(event):
693 fun()
694 if key is None:
695 self.cv.bind("<KeyPress>", eventfun)
696 else:
697 self.cv.bind("<KeyPress-%s>" % key, eventfun)
698
699 def _listen(self):
700 """Set focus on canvas (in order to collect key-events)

Callers 1

onkeypressMethod · 0.80

Calls 2

unbindMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected