MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / _onclick

Method _onclick

Python/Turtle.py:502–515  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

onclickMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected