Question

when an entry in a Tk::HList is selected by a single click, a dotted line is drawn around this entry. I don't want to have this line. How can I configure it? I don't see any documented way to do it.

Here is some example code showing a Tk::HList with a pre-selected entry. When you click the entry, a dotted line will appear.

#!perl

use strict;
use warnings;
use utf8;
use Tk;
use Tk::HList;

my $mw = tkinit();

# -- create a Tk::HList
my $scrolled_hlist = $mw->Scrolled('HList',
    -scrollbars => 'se',
    -columns => 2,
    -header => 1,
    -width => 50,
    -height => 20,
    # hide black border around HList when it's active
    -highlightthickness => 0,
    -selectborderwidth => 1,
    -selectmode => 'single',

)->pack(-fill => 'y', -expand => 1,);

my $real_hlist = $scrolled_hlist->Subwidget('scrolled');


# -- add HList header colums
$real_hlist->header(
    'create', 0,
    -text   => 'first column',
);

$real_hlist->header(
    'create', 1,
    -text   => 'second column',
);


# -- add some entries to the HList
$real_hlist->add(1);
$real_hlist->item('create', 1, 0, -text => 'first row, 1st col');
$real_hlist->item('create', 1, 1, -text => 'first row, 2nd col');

$real_hlist->add(2);
$real_hlist->item('create', 2, 0, -text => '2nd row, 1st col');
$real_hlist->item('create', 2, 1, -text => 'second row, 2nd col');


# -- set selection *** without dashed line border ***
$real_hlist->selectionSet(2);

$mw->MainLoop();
exit(0);
Was it helpful?

Solution

It took some time to find it, but the solution is to call anchorClear() as browsecmd:

#!perl

use strict;
use warnings;
use utf8;
use Tk;
use Tk::HList;

my $mw = tkinit();

# -- create a Tk::HList
my $scrolled_hlist = $mw->Scrolled('HList',
    -scrollbars => 'se',
    -columns => 2,
    -header => 1,
    -width => 50,
    -height => 20,
    # hide black border around HList when it's active
    -highlightthickness => 0,
    -selectborderwidth => 1,
    -selectmode => 'single',
)->pack(-fill => 'y', -expand => 1,);

my $real_hlist = $scrolled_hlist->Subwidget('scrolled');
$real_hlist->configure(
    -browsecmd => [ sub{ $_[0]->anchorClear(); }, $real_hlist],
);

# -- add HList header colums
$real_hlist->header(
    'create', 0,
    -text   => 'first column',
);

$real_hlist->header(
    'create', 1,
    -text   => 'second column',
);


# -- add some entries to the HList
$real_hlist->add(1);
$real_hlist->item('create', 1, 0, -text => 'first row, 1st col');
$real_hlist->item('create', 1, 1, -text => 'first row, 2nd col');

$real_hlist->add(2);
$real_hlist->item('create', 2, 0, -text => '2nd row, 1st col');
$real_hlist->item('create', 2, 1, -text => 'second row, 2nd col');


# -- set selection *** without dashed line border ***
$real_hlist->selectionSet(2);

$mw->MainLoop();
exit(0);

Source: https://groups.google.com/d/topic/comp.lang.perl.tk/iCE7ql2Bw4E/discussion

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top