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