in reply to Colorizing the labels in Tk::RadiobuttonGroup

The script below has a scheme for button colouring that may give you some help.

$SIG{CHLD} = "IGNORE"; use Tk; use Grid; use Getopt::Long; $rhOpts = { "cols" => \$cols, "group" => \$group, "dt" => \$dt}; $optResult = &GetOptions($rhOpts, "cols=i", "group=s", "dt"); exit(1) unless $optResult; $netgroup = $group ? $group : "sunbox"; open YP, "/usr/bin/ypmatch $netgroup netgroup |" or die "$0: Unable to ypmatch nodes\n"; $_ = <YP>; @nodeList = /\(([a-z0-9]+),,/g; close YP; @nodeList = sort @nodeList; unshift @nodeList, "Local"; $numHosts = scalar @nodeList; $longestName = 0; foreach (@nodeList) { my $l = length; $longestName = $l if $l > $longestName; } $bgColour = "LightSteelBlue3"; %labelColours = ( -foreground => "NavyBlue", -background => "LemonChiffon"); %buttonColours = ( -background => "grey35", -foreground => "yellow2", -activebackground => "grey45", -activeforeground => "yellow", -disabledforeground => "grey55"); %commonRadioButtonOpts = ( -width => 6, -selectcolor => "red", -relief => "raised", -borderwidth => 2, -padx => 5, -pady => 5); $mainWin = MainWindow->new( -background => $bgColour); $mainWin->title("xrem"); $mainWin->resizable(0, 0); $hostSelectFrame = $mainWin->Frame( -relief => "ridge", -background => $bgColour, -borderwidth => 2)->pack( -side => "top", -fill => "y", -expand => 1); if($cols) { unless($cols =~ m<^[23456]$>) { print "Invalid columns value supplied, using two columns\n"; $cols = 2; } } $numCols = $cols ? $cols : 2; $rlButtonOrder = fitToColsVSort($numHosts, $numCols); foreach (0 .. $#nodeList) { my $buttonName = $nodeList[$_] . "Button"; $$buttonName = $hostSelectFrame->Button( -text => $nodeList[$_], -background => $nodeList[$_] =~ m<^Local$> ? "#006600" : "grey35", -foreground => "yellow2", -activebackground => $nodeList[$_] =~ m<^Local$> ? "#008600" : "grey45", -activeforeground => "yellow", -disabledforeground => "grey55", -width => $longestName)->grid( -row => $rlButtonOrder->[$_]->[0], -column => $rlButtonOrder->[$_]->[1], -padx => 5, -pady => 5); $$buttonName->configure( -command => [\&gotoHost, $nodeList[$_]]); } $termType = $dt ? 0 : 1; $termTypeFrame = $mainWin->Frame( -relief => "flat", -background => $bgColour, -borderwidth => 2)->pack( -side => "top"); $termTypeFrame->Radiobutton( -text => "xterm", %commonRadioButtonOpts, %buttonColours, -value => 1, -variable => \$termType)->pack( -side => "left", -padx => 5, -pady => 5); $termTypeFrame->Radiobutton( -text => "dtterm", %commonRadioButtonOpts, %buttonColours, -value => 0, -variable => \$termType)->pack( -side => "left", -padx => 5, -pady => 5); $mainWin->update(); $barWidth = $hostSelectFrame->width() - 2; $ridgeBar = $mainWin->Canvas( -borderwidth => 0, -width => $barWidth, -height => 2,)->pack( -side => "top"); $ridgeBar->createLine(0, 0, $barWidth - 1, 0, -fill => "grey10"); $ridgeBar->createLine(0, 1, $barWidth - 1, 1, -fill => "grey30"); $termCols = 0; $termRows = 0; $termSizeFrame = $mainWin->Frame( -relief => "flat", -background => $bgColour, -borderwidth => 2)->pack( -side => "top"); $leftTermSizeFrame = $termSizeFrame->Frame( -relief => "flat", -background => $bgColour, -borderwidth => 0)->pack( -side => "left"); $rightTermSizeFrame = $termSizeFrame->Frame( -relief => "flat", -background => $bgColour, -borderwidth => 0)->pack( -side => "left"); $leftTermSizeFrame->Label( %labelColours, -text => "Columns", -relief => "sunken", -borderwidth => 2, -justify => "left", -padx => 5, -pady => 5)->pack( -side => "top"); $leftTermSizeFrame->Radiobutton( -text => "80", %commonRadioButtonOpts, %buttonColours, -value => 0, -variable => \$termCols)->pack( -side => "top", -padx => 5, -pady => 5); $leftTermSizeFrame->Radiobutton( -text => "100", %commonRadioButtonOpts, %buttonColours, -value => 1, -variable => \$termCols)->pack( -side => "top", -padx => 5, -pady => 5); $leftTermSizeFrame->Radiobutton( -text => "132", %commonRadioButtonOpts, %buttonColours, -value => 2, -variable => \$termCols)->pack( -side => "top", -padx => 5, -pady => 5); $rightTermSizeFrame->Label( %labelColours, -text => "Rows", -relief => "sunken", -borderwidth => 2, -justify => "left", -padx => 5, -pady => 5)->pack( -side => "top"); $rightTermSizeFrame->Radiobutton( -text => "24", %commonRadioButtonOpts, %buttonColours, -value => 0, -variable => \$termRows)->pack( -side => "top", -padx => 5, -pady => 5); $rightTermSizeFrame->Radiobutton( -text => "35", %commonRadioButtonOpts, %buttonColours, -value => 1, -variable => \$termRows)->pack( -side => "top", -padx => 5, -pady => 5); $rightTermSizeFrame->Radiobutton( -text => "50", %commonRadioButtonOpts, %buttonColours, -value => 2, -variable => \$termRows)->pack( -side => "top", -padx => 5, -pady => 5); $controlButtonFrame = $mainWin->Frame( -relief => "flat", -background => $bgColour, -borderwidth => 2)->pack( -side => "top"); $controlButtonFrame->Button( -text => "Quit", %buttonColours, -command => sub {exit;})->pack( -side => "right", -padx => 5, -pady => 5); MainLoop(); sub gotoHost { my $host = shift; my @cols = qw(80 100 132); my @rows = qw(24 35 50); my $cmd = $termType ? "/usr/openwin/bin/xterm -sb -sl 2000 -title $host " : "/usr/dt/bin/dtterm -title $host -n $host "; $cmd .= "-geometry $cols[$termCols]x$rows[$termRows]"; $cmd .= " -e /usr/bin/telnet $host" unless $host eq "Local"; my $pid; if($pid = fork) { return; } elsif(defined($pid)) { exec $cmd; } else { die "Fork error: $!\n"; } }

The code is a bit old and creaky but the Tk stuff should be relevant to your problem. I hope it is of use.

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^2: Colorizing the labels in Tk::RadiobuttonGroup
by indigosplinter (Novice) on Jun 28, 2006 at 14:18 UTC
    That does help, thanks. Breaking up my list into individual radiobuttons did the trick. It seems that the 'radiobuttongroup' function doesn't support the label colors the way the stand-alone one does. Too bad, but its just more lines of code. A lot more.