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)
| 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) |
no test coverage detected