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

I'm developing a Perl/Tk app that connects to a list of servers and performs various tasks. Each server gets a row in the HList, and each task gets a column. If the task fails, an appropriate message is placed in that cell. However, I'd like to turn the background of that row red so it stands out from the list (there are approx. 250 rows and it's hard to see). I've looked into using custom tags for this, but it seems that tags are not supported by HList.

Thanks!
ookami
  • Comment on how to set a different background colour on certain rows in an HList widget?

Replies are listed 'Best First'.
Re: how to set a different background colour on certain rows in an HList widget?
by jdporter (Paladin) on Aug 17, 2004 at 18:35 UTC

    The documentation states that the items that get added to an HList are DItem's. If the DItem is of the appropiate type (e.g. text and imagetext), you can apply an ItemStyle, the attributes of which include background color.

    See the manpage of Tk::DItem for details. Then see the Tk::HList manpage for an explanation of how to create custom DItems and add them to an HList.

Re: how to set a different background colour on certain rows in an HList widget?
by eserte (Deacon) on Aug 18, 2004 at 13:41 UTC
    Look at the 2nd HList entry in the "widget" demonstration. That snippet demonstrates how to use multiple columns, different fonts, background and foreground colors per cell, and how to add images and custom widgets.
Re: how to set a different background colour on certain rows in an HList widget?
by zentara (Cardinal) on Aug 18, 2004 at 13:22 UTC
    I did something similar in ztkdb, here is the routine. As you can see in the change_col sub, you need to set a 'textstyle' and use -style
    ############################################################## sub select_color{ my $dialogcol = $mw->Toplevel(-bg=>'steelblue'); $dialogcol->overrideredirect(1); $dialogcol->geometry('+100+100'); $dialogcol->configure(-cursor => 'top_left_arrow'); my @colors = qw(DarkGrey orange pink hotpink red peru goldenrod tan gold wheat lightyellow yellow khaki lightgreen green lightsteelblue turquoise cyan violet plum bisque beige snow); my ($r,$c)=(0,0); foreach my $color(@colors){ $dialogcol->Button( -text =>$color, -bg=> $color, -width=> 12, -activebackground=>$color, -command => [\&change_col,$color], )->grid(-column => $c, -row => $r); $c++; if($c % 5 == 0){$r++;$c = 0}; } $dialogcol->Button( -text => 'Finished', -bg=>'red', -activebackground=>'plum', -command => sub{$dialogcol->destroy; })->grid(-column=>$c, -row=> $r+1); sub change_col{ $info{$key_sel}{'color'} = shift; $colorbut->configure(-bg=> $info{$key_sel}{'color'}); my $textstyle = $h->ItemStyle('text', -justify => 'center', -bg => $info{$key_sel}{'color'}, -selectforeground => 'green', ); $h->itemConfigure($h->info('selection'), 1,'-style'=>$textstyle); } }

    I'm not really a human, but I play one on earth. flash japh