I'm writing an Explorer-like application using the tkinter listbox. On a double click, I want to enter the selected folder, so I clear the list and input the folders content.
When I click directly after I double-clicked, it is still considered as a new double-click. Thus, no single-click is performed, meaning no list box entry is selected and a change occurs before I actually double-clicked again.
Is there a way to "reset" the double-click so my program will consider the next click a single-click no matter what I did before?
I tried to use the click event coordinate to get the "double-clicked" entry, but this will fire at the third instead of the fourth click, which is not desired behaviour. I also tried to bind a triple-click to block off a second double click, but then the program won't respond if I click more than 3 times and only react again after a delay.
import tkinter as tk
import random
def fill_box(event):
"""Clear and refresh listbox"""
try:
listbox.get(listbox.curselection()[0])
selection = True
except IndexError:
selection = False
print("Event:", event, "Selection:", selection)
listbox.delete(0, tk.END)
for _ in range(10):
listbox.insert(tk.END, random.randint(0, 1000))
root = tk.Tk()
listbox = tk.Listbox(root)
for _ in range(10):
listbox.insert(tk.END, random.randint(0, 1000))
listbox.bind("<Double-Button-1>", fill_box)
# listbox.bind("<Triple-Button-1>", lambda x: 1) # Triple click
listbox.pack()
root.mainloop()
My Expectation is that after I double-clicked an entry, I can immediately interact with the GUI again without having to wait for a double-click cooldown to pass. Also, I do not want to double-click new entries with (relative to the current view) single click.