Bind fun to mouse-click event on turtle. 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
(self, item, fun, num=1, add=None)
| 602 | ## """may be implemented for some other graphics toolkit""" |
| 603 | |
| 604 | def _onclick(self, item, fun, num=1, add=None): |
| 605 | """Bind fun to mouse-click event on turtle. |
| 606 | fun must be a function with two arguments, the coordinates |
| 607 | of the clicked point on the canvas. |
| 608 | num, the number of the mouse-button defaults to 1 |
| 609 | """ |
| 610 | if fun is None: |
| 611 | self.cv.tag_unbind(item, "<Button-%s>" % num) |
| 612 | else: |
| 613 | def eventfun(event): |
| 614 | x, y = (self.cv.canvasx(event.x)/self.xscale, |
| 615 | -self.cv.canvasy(event.y)/self.yscale) |
| 616 | fun(x, y) |
| 617 | self.cv.tag_bind(item, "<Button-%s>" % num, eventfun, add) |
| 618 | |
| 619 | def _onrelease(self, item, fun, num=1, add=None): |
| 620 | """Bind fun to mouse-button-release event on turtle. |
no test coverage detected