Trigger an event after two clicks on button

Asked

Viewed 421 times

3

I am developing a small interface in Tkinter, but I have the following question: Is there a mouse event that allows an action to be executed after two clicks consecutive on a button?

1 answer

4


There is, the method bind, you can inform the event, which can be:

  • <Button-1>: A click.
  • <Double-Button-1>: Two clicks.
  • <Triple-Button-1>: Three clicks.
  • Among others...

Take an example:

from tkinter import *

def foo():
    print ('foo')

root = Tk()

frame = Frame(root)
frame.pack()

button1 = Button(frame, text = 'Foo!')
button1.pack()
button1.bind('<Double-Button-1>', foo)

root.mainloop()

For more information see the documentation: Events and Bindings.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.