in reply to Perl::Tk radiobutton yet one more time
The reason they are different, is that on Windows, the Tk low level code uses the themed radiobuttons provided by windows. The shapes are not in the module.
If you want them to look exactly the same, you will have to use the -image and -selectimage options. This would involve making a set off small images, 1 for on, 1 for off, for each radiobutton. I probably would use a graphics module like GD to make them dynamically. Here is a crude example, and you would need to make one for "off", and one for "on", for each radiobutton. Gd images can be written to scalars, so you can do this all without writing any temp files. See the second example below. It sure seems like alot of useless overhead. I would be tempted to make my own custom widget on a Tk::Canvas, rather than make all the images, especially for a large button list.
Anyways, a crude -select image generator for you.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::PNG; use GD; use MIME::Base64; my $image_on = new GD::Image(50,50); my $image_off = new GD::Image(50,50); my $green = $image_on->colorAllocate(0,255,0); my $red = $image_off->colorAllocate(255,0,0); my $white = $image_on->colorAllocate(255,255,255); my $white1 = $image_off->colorAllocate(255,255,255); #$image->filledEllipse($cx,$cy,$width,$height,$color) $image_on->filledRectangle( 0, 0, 50, 50, $white ); $image_off->filledRectangle( 0, 0, 50, 50, $white1 ); $image_on->filledEllipse(25,25,20,20,$green); $image_off->filledEllipse(25,25,20,20,$red); my $gdimage_on; my $gdimage_off; open( IMAGE, ">",\$gdimage_on) || die "$!\n"; binmode( IMAGE ); print IMAGE $image_on->png(); close IMAGE; open( IMAGE, ">",\$gdimage_off) || die "$!\n"; binmode( IMAGE ); print IMAGE $image_off->png(); close IMAGE; my %wb; my $mw = new MainWindow; $mw->geometry('400x400'); $mw->fontCreate('big', -weight=>'bold', -size=> 18 ); my $im_on = $mw->Photo(-data => encode_base64($gdimage_on)); my $im_off = $mw->Photo(-data => encode_base64($gdimage_off)); foreach my $rb (qw/1 2 3 4/) { $wb{'frame'} = $mw->Frame()->pack(); $wb{'label'} = $wb{'frame'}->Label(-text => $rb, -justify => 'left', -anchor => 'w', -font => 'big', )->pack(-side => 'left'); $wb{$rb} = $wb{'frame'}->Radiobutton( -text => $rb, -relief => 'flat', -value => $rb, -indicatoron => 0, -width => 12, -background => 'white', -image => $im_off, -selectimage => $im_on, -command => [\&cb_rbutton, $rb], )->pack(-side => 'left'); } MainLoop; sub cb_rbutton { my $rb = shift; print $rb, " is on\n"; return; }
|
|---|