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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.