1

I found a lot of questions about canvas mouse events but nothing with python

so my question is: how do I use mouse events in python canvas

If this question is quite weard, this is my first question on stack overflow

Mike67
  • 11,175
  • 2
  • 7
  • 15

1 Answers1

0

You can have a look here: http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm for an introduction on events binding.

A canvas is a widget so you can bind mouse events to it like:

def on_left_button_clicked(event):
   # retrieve mouse properties eg coordinates from the event


c = tk.Canvas(root,....)
c.grid(...) # or pack
c.bind("<Button-1>", on_left_button_clicked)

Contrary to other widgets, the canvas provides helper function to related mouse coordinates to canvas ones (because the canvas can be "dragged"). See here for canvas specificities: http://www.effbot.org/tkinterbook/canvas.htm

Jean-Marc Volle
  • 3,113
  • 1
  • 16
  • 20