I'm new to tkinter and I'm coding a simple "Paint" program, that draws a pixel on screen when I press my mouse.
So i tried to bind my function "is_pressed" like this:
#is pressed
def is_pressed(event):
print('Mouse is pressed!')
#creating canvas
my_canvas = tkinter.Canvas(height=400, width=600)
my_canvas.pack()
#binding
my_canvas.bind('<Button-1>', is_pressed)
Now, I want this function to run when mouse is pressed, not when it's just clicked. How do i do it?
For something like 'painting' with the mouse, I've usually used
bind('<B1-Motion>', <callback>)Naturally, you can bind this to other buttons using
B2orB3instead.The caveat here is that the event doesn't trigger immediately - you have to move the mouse first. You could easily bind a second handler to
<'Button-1'>though