Bind fun to mouse-move-event (with pressed mouse button) on turtle. fun must be a function with two arguments, the coordinates of the actual mouse position on the canvas. num, the number of the mouse-button defaults to 1 Every sequence of mouse-move-events on a turtl
(self, item, fun, num=1, add=None)
| 534 | eventfun, add) |
| 535 | |
| 536 | def _ondrag(self, item, fun, num=1, add=None): |
| 537 | """Bind fun to mouse-move-event (with pressed mouse button) on turtle. |
| 538 | fun must be a function with two arguments, the coordinates of the |
| 539 | actual mouse position on the canvas. |
| 540 | num, the number of the mouse-button defaults to 1 |
| 541 | |
| 542 | Every sequence of mouse-move-events on a turtle is preceded by a |
| 543 | mouse-click event on that turtle. |
| 544 | """ |
| 545 | if fun is None: |
| 546 | self.cv.tag_unbind(item, "<Button%s-Motion>" % num) |
| 547 | else: |
| 548 | def eventfun(event): |
| 549 | try: |
| 550 | x, y = (self.cv.canvasx(event.x)/self.xscale, |
| 551 | -self.cv.canvasy(event.y)/self.yscale) |
| 552 | fun(x, y) |
| 553 | except Exception: |
| 554 | pass |
| 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. |