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)
| 500 | ## """may be implemented for some other graphics toolkit""" |
| 501 | |
| 502 | def _onclick(self, item, fun, num=1, add=None): |
| 503 | """Bind fun to mouse-click event on turtle. |
| 504 | fun must be a function with two arguments, the coordinates |
| 505 | of the clicked point on the canvas. |
| 506 | num, the number of the mouse-button defaults to 1 |
| 507 | """ |
| 508 | if fun is None: |
| 509 | self.cv.tag_unbind(item, "<Button-%s>" % num) |
| 510 | else: |
| 511 | def eventfun(event): |
| 512 | x, y = (self.cv.canvasx(event.x)/self.xscale, |
| 513 | -self.cv.canvasy(event.y)/self.yscale) |
| 514 | fun(x, y) |
| 515 | self.cv.tag_bind(item, "<Button-%s>" % num, eventfun, add) |
| 516 | |
| 517 | def _onrelease(self, item, fun, num=1, add=None): |
| 518 | """Bind fun to mouse-button-release event on turtle. |