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

Hello Monks,

I cannot understand: how to make the black border not to appear around the Tree widget just after the first hiding/showing (pushing signs -/+) inside this widget? It breaks the style of the all window.

The Tree is managed by grid; it's itemtype is 'window' (because contains labels and checkbuttons).

I tried to set borderwidth and selectborderwidth both to 0. It didn't help.

In short, my code looks like:

$tree-> = $pane->Tree( -width => 30, -height => 1500, -itemtype => 'window', -relief => 'flat', -borderwidth => 0, -selectborderwidth => 0 )->grid( -row => $row, -column => 0, -columnspan => 2, -sticky => 'w' );

Then, inside a loop:

my $ref1 = $tree->Label( -text => $_, -anchor => 'w' ); $tree->add( $_, -window => $ref1 );

And then, inside another loop:

my $ref2 = $tree->Checkbutton( -text => $_, -variable => \$var, -anchor => 'w' ); $tree->add( $parent.'.'.$column, -window => $ref2 );

Replies are listed 'Best First'.
Re: Perl/Tk, how to make the black border not to appear around the Tree widget
by zentara (Cardinal) on Nov 10, 2009 at 17:55 UTC
    ...its always nice to give a complete, minimal running example, so we can run your code without having to flesh it out ourselves....but i see the problem

    ...i think you have a focus problem.... read perldoc Tk::focus....

    if your main concern is stopping this normal widget behavior, for asthetic reasons, you might want to make your own custom widget that responds exactly the way you want

    ... some Tk widgets are so locked into this type of behavior, that the only way around it is to match colors for the highlight and select modes, so it appears invisible

    ....the first thing i would try, is to but in a -browsecmd callback in your tree, and in that callback force the focus back to the mainwindow, like

    -browsecmd => sub{ $mw->focus }
    or some dynamic hack that keeps the focus elsewhere..... but then again ,it might break the way the widget works..... back to making your own widgets :-)

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku

      Thank you much for the reply, Zentara,

      >...its always nice to give a complete, minimal running example, so we can run your code without having to flesh it out ourselves
      It's all deep inside different loops, with multiple hash keys and array indexes. But OK, you're right. Next time I'll do it, anyway...

      After adding your browsecmd, the black border appears for a moment and then goes. Thanks a lot, you have shown me the main problem!

      Yes, I have only asthetic reasons... And yes, I checked, 'highlight' option changes the color of the border. So, I miss only the right color name for my background (the default like silver?).

      Thank you again!

        hi...each widget in Tk seems to respond to a different set of options.... its a haphazrd collection of options.... so here is another little secret

        read perldoc Tk::options and see the other options available ( that the Tree author didn't put in his docs).... there is an option for "highlightthickness".... you might see if that works, put a value for 0 or 1 in there and see if it helps.

        ...as to the other trick, about matching colors...in Tk::options there are some options for background and highlightbackground colors..... they may not respond to the Tree though....that is the trouble with Tk.....it's not a coherent widget set and inherited object system...... next project, think Gtk2


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku