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

Method _onkeypress

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

686 self.cv.bind("<KeyRelease-%s>" % key, eventfun)
687
688 def _onkeypress(self, fun, key=None):
689 """If key is given, bind fun to key-press event of key.
690 Otherwise bind fun to any key-press.
691 Canvas must have focus. See method listen.
692 """
693 if fun is None:
694 if key is None:
695 self.cv.unbind("<KeyPress>", None)
696 else:
697 self.cv.unbind("<KeyPress-%s>" % key, None)
698 else:
699 def eventfun(event):
700 fun()
701 if key is None:
702 self.cv.bind("<KeyPress>", eventfun)
703 else:
704 self.cv.bind("<KeyPress-%s>" % key, eventfun)
705
706 def _listen(self):
707 """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