0

当通过单击选择 Tk::HList 中的条目时,将在该条目周围绘制一条虚线。我不想有这条线。我该如何配置它?我没有看到任何记录在案的方法。

下面是一些示例代码,显示了带有预选条目的 Tk::HList。单击该条目时,将出现一条虚线。

#!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);
4

1 回答 1

1

找到它花了一些时间,但解决方案是调用 anchorClear() 作为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);

资料来源:https ://groups.google.com/d/topic/comp.lang.perl.tk/iCE7ql2Bw4E/discussion

于 2012-09-18T21:17:02.627 回答