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