Bind fun to mouse-click event on canvas. fun must be a function with two arguments, the coordinates of the clicked point on the canvas. num, the number of the mouse-button defaults to 1 If a turtle is clicked, first _onclick-event will be performed, then _ons
(self, fun, num=1, add=None)
| 555 | self.cv.tag_bind(item, "<Button%s-Motion>" % num, eventfun, add) |
| 556 | |
| 557 | def _onscreenclick(self, fun, num=1, add=None): |
| 558 | """Bind fun to mouse-click event on canvas. |
| 559 | fun must be a function with two arguments, the coordinates |
| 560 | of the clicked point on the canvas. |
| 561 | num, the number of the mouse-button defaults to 1 |
| 562 | |
| 563 | If a turtle is clicked, first _onclick-event will be performed, |
| 564 | then _onscreensclick-event. |
| 565 | """ |
| 566 | if fun is None: |
| 567 | self.cv.unbind("<Button-%s>" % num) |
| 568 | else: |
| 569 | def eventfun(event): |
| 570 | x, y = (self.cv.canvasx(event.x)/self.xscale, |
| 571 | -self.cv.canvasy(event.y)/self.yscale) |
| 572 | fun(x, y) |
| 573 | self.cv.bind("<Button-%s>" % num, eventfun, add) |
| 574 | |
| 575 | def _onkeyrelease(self, fun, key): |
| 576 | """Bind fun to key-release event of key. |