Trigger an event after two button clicks

2

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

    
asked by anonymous 12.10.2016 / 01:44

1 answer

3

There is, yes, 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 ...

See 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 .

    
12.10.2016 / 02:39