#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import tkinter as tk
from tkinter import ttk, font
class Intento1(tk.Frame):
def __init__(self, master, *args, **kwargs):
super().__init__(master, *args, **kwargs)
labeltop = tk.Label(master, text= "Etiqueta superior", background = "red")
labeltop.grid(row=0, column=0)
labeltop.bind("<Button-1>", self.callLabelTop)
labeltop.bind("<Double-Button-1>", self.callLabelTopDouble)
self.quitButton = tk.Button(master, text="quit", command=self.quit)
self.quitButton.grid(row=1, column=0)
def callLabelTop(self, event):
print("Intento1: Single click in TopLabel")
def callLabelTopDouble(self, event):
print("Intento1: Double click in TopLabel")
if __name__ == "__main__":
print(sys.version)
root = tk.Tk()
app = Intento1(root)
root.progID = sys.argv[0] + " --> " # recoge nombre del programa
root.title(root.progID + 'Sample application')
root.mainloop()
When I double click on the label, the single click and double click events are fired at the same time.
What am I doing wrong or what am I missing? Is it standard behavior?
The stackoverflow interface asks me to add more details, to let me post. I think that what is described is enough, right?
As @Franco already commented, it is the expected behavior. However we can do something, implement our own method to handle the event.
Actually, a double click is nothing more than two clicks in a row in a short time interval, every time we have a click we can check if another click occurs in
t
milliseconds, if it does not occur we have a simple click, if a double click occurs. For this we can make use ofafter
:In this case the time is 300 ms, we can adjust it if we wish. Obviously this makes a simple click event take 300 ms to display, but this is impossible to avoid if we don't want to fire both.