如何删除Tk :: HList中选区的虚线?

时间:2012-09-17 20:25:11

标签: perl tk perltk hlist

通过单击选择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);

1 个答案:

答案 0 :(得分: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