here is monkeypatching proof of concept, use bbox to get coordinates of the listitem, math, compare to mouse coordinates
#!/usr/bin/perl -- $Devel::Trace::TRACE = 0; ## off use strict; use warnings; use Tk; my $mw = MainWindow ->new ; my $listFrame = $mw->Frame->pack; my $listBox = $listFrame->Scrolled( 'Listbox', -scrollbars => 'osoe', -selectmode => 'extended', -background => 'white', -height => 10, -width => 10, -selectborderwidth => 0, -relief => 'flat', )->pack; $listBox->insert('end', qw/red yellow green blue grey/); @ARGV and eval { require Tk::WidgetDump; $mw->WidgetDump; }; MainLoop; exit 0; # BeginSelect -- # # This procedure is typically invoked on button-1 presses. It begins # the process of making a selection in the listbox. Its exact behavior # depends on the selection mode currently in effect for the listbox; # see the Motif documentation for details. # # Arguments: # w - The listbox widget. # el - The element for the selection operation (typically the # one under the pointer). Must be in numerical form. sub Tk::Listbox::BeginSelect { package Tk::Listbox; use vars qw/ @Selection $Prev /; $Devel::Trace::TRACE = 1; ## on my $w = shift; my $el = shift; if ( $w->cget('-selectmode') eq 'multiple' ) { if ( $w->selectionIncludes($el) ) { $w->selectionClear($el); } else { $w->selectionSet($el); } } else { ## fix it here my ( $iltx, $ilty, $iw, $ih ) = $w->bbox($el); my $rooty = $listBox->rooty; my $evY = $Tk::event->Y; my $ylt = $rooty + $ilty + $ih; print "$ylt < $evY\n"; if ( $ylt < $evY ) { ### clear the board when clicking off the end ### no selection ### anchor $w->selectionClear( 0, 'end' ) } else { ## the original logic $w->selectionClear( 0, 'end' ); $w->selectionSet($el); $w->selectionAnchor($el); } @Selection = (); $Prev = $el; } $w->focus if ( $w->cget('-takefocus') ); $w->eventGenerate("<<ListboxSelect>>"); $Devel::Trace::TRACE = 0; ## off }

In reply to Re^2: How to determine if nothing is selected in a listbox (only select actually clicked element) with bbox by Anonymous Monk
in thread How to determine if nothing is selected in a listbox by simonz

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.