Most GUI systems do exactly this; that's why the single-click action (e.g. 'select a file') is usually implied by the double-click action (e.g. 'open a file').
I'm not too familiar with Tk, but what you want to do is likely to set some sort of 'timeout callback' that is registered with your main loop (or with Tk?) when a single-click is registered, and then cancel that callback if the double-click is received.
So, e.g.:
<pseudocode> sub callback_A { $global{click_timeout} = set_timeout (after=>($config{double_click_time} * 1.5), do=>sub { &callback_A_really(@_); } ); } sub callback_B { cancel_timeout ($global{click_timeout}); # do double-click event } sub callback_A_really { # do single-click event } </pseudocode>
Of course, callback_A_really could be coded directly into the anonymous sub (closure, da?) in this example, but only if your main loop can handle a timeout like this. The *1.5 is there to ensure that a double-click right on the 'threshold' of being valid doesn't enter a sort of race condition with the timeout.
If Tk doesn't have a similar timeout feature, you can fall back to using POSIX 'alarm' or similar. (But I don't know if that's portable to Win32 | MacOS ?)
My real suggestion, though, would be to evade the problem by 'using the UI the usual way.' What are you trying to do in a case like this that would benefit from not using the standard UI semantics, i.e. a single-click is implied by the first click in a double-click sequence? I'd expect you to thoroughly confuse your user if you implement something like that...
A good reference is the Macintosh Human Interface Guidelines (this is for System 8)... there are good reasons they did things the way they did :-)
In reply to Re: Tk click/doubleclick
by Anonymous Monk
in thread Tk click/doubleclick
by Jouke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |