andy4321 has asked for the wisdom of the Perl Monks concerning the following question:

The code below is the smallest example I could come up with.

There are two curiosities that I'd like to figure-out.

  1. When I double-click (left-mouse-button), a small dashed box appears around the entry that's been clicked
  2. When I double-click (left-mouse-button), the entry changes color from green to black (still with Courier 12 bold)

When I single (left-click) the window not containing an entry, then the entry that was clicked returns to being displayed as DarkGreen with no highlight box round it.

Questions (somewhat inter-related):

  1. Is it possible to disable HList from responding to the double-left-click (so that the entry doesn't get a dashed-box and the color of the entry doesn't change)?
  2. On other GUIs I've written, the dashed-box has proved annoying. Is it possible to prevent the dashed-box from appearing?

Thank you for your time.

#!/usr/bin/perl use Tk; use Tk::HList; use Tk::ItemStyle; use File::Basename; $FONT_BOLD = "Courier 12 bold"; $mw = MainWindow->new(-title => $0); $hlist = $mw->HList(-selectmode=>"none", -selectbackground=>"Wheat", -selectborderwidth=>0, -background=>"Wheat", -selectbackground=>"Wheat", -separator=>"/", -drawbranch=>1, -indicator=>1, ) -> pack(qw/-fill both -expand yes/); $Highlight = $mw->ItemStyle('text', -foreground=>"DarkGreen", -backgro +und=>"Wheat", -font=>$FONT_BOLD); foreach $path("/", "/home", "/home/andrew") { $hlist -> add($path, -text=>basename($path), -style=>$Highlight); } MainLoop();

Replies are listed 'Best First'.
Re: Double-clicking a HList Entry
by choroba (Cardinal) on Mar 30, 2025 at 16:36 UTC
    Selectmode "none" doesn't seem to be documented.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Thank you for your reply

      The supported options for -selectmode are: single, browse, multiple and extended

      I tried none just to see if it made a difference ... which it didn't.

      I've also tried binding to double-left-click with something like:

      $hlist -> bind("<Double-Button-1>" => \&DoubleClicked); sub DoubleClicked { my @selected = $hlist->selectionGet(); my $entry = $selected[0]; print "DoubleClicked: $entry\n"; $hlist->hide('entry', $entry); $mw->update(); sleep(1); $hlist->show('entry', $entry); }

      The sleep was me just doing a simple experiment to see what would happen (I know Callbacks should complete as quickly as possible).

      I've also noticed that:

      • -selectforeground=>"Red" has no effect when a style is given to a HList entry
      • That is, -selectforeground works fine as long as I don't apply a style.
      • So there is some interaction between the two.

      My next attempt is to delete the HList and re-populate ... which seems a bit extreme.