tk_list_selection_example_0.py
tk_list_selection_example_0.py demonstrates capturing mouse clicks, per request.
Starting point was http://www.codeskulptor.org/#examples-list_selection.py. I did not use a list and did not use an equivalent to the draw handler. Instead I simply drew a circle on the Canvas at each mouse click. The original example would change the color from red to green if you clicked inside an existing circle but I'm not going to include that. Some key things to look for in the conversion:
- simplegui returns pos with the mouse coordinates but tkinter returns event.x and event.y, so you have to translate those accordingly.
- Ball drawing is different. Instead of a circle with a center point and radius like simplegui, tkinter requires you to draw an .oval with the upper-left and lower-right points defined, so another translation.
- Note I have two mouse handlers, depending on which Widget you are clicking (Canvas vs Frame).
- Notice the canvas.bind("<Button-1>", click) syntax ... Button-1 is the left mouse button but there are options to bind to other buttons or to double clicks, etc.