UPDATE Sept 22,2011 Made the example code better, actually only 2 small GD images are needed
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;
}
| [reply] [d/l] |
This is the last time I'm asking this, yet agian, sorry
The answer doesn't change :)
Native look and feel means it looks different on each platform, even if by mistake
Is the platform showing the diamond instead of circle for radiobutton using the latest perl/Tk? Tk-804.029_500 ?
If the answer is yes, there is nothing you can do :)
Tk::Radiobutton just doesn't let you choose what kind of indicator, circle or diamond
You could try setting tkvars$Tk::strictMotif, but I doubt it would help
short of implementing your own widgets, say, using Tk::Canvas, Tk::ImageButton..., there is nothing you can do
If you upgrading Tcl/Tk and switching to Tcl::pTk, maybe it allows you to change Styles and Themes, maybe using tile ...
Prima on the other hand should look the same on all platforms
http://en.wikipedia.org/wiki/List_of_widget_toolkits ... Clutter / http://www.clutter-project.org/about/whos-using-clutter
| [reply] |
This should get you up and running....
#!usr/bin/perl
use strict;
use Tk;
my $top = MainWindow->new;
my $color = qw/Green Blue Yellow Red White/;
my @wb;
$wb[0] = $top->Radiobutton(
-variable => \$color,
-command => [\&cb_rbutton, $top],
-text => 'Green',
-value => 'green')->pack(
-side => 'top',
-anchor => 'w');
$wb[1] = $top->Radiobutton(
-variable => \$color,
-command => [\&cb_rbutton, $top],
-text => 'Blue',
-value => 'blue')->pack(
-side => 'top',
-anchor => 'w');
$wb[2] = $top->Radiobutton(
-variable => \$color,
-command => [\&cb_rbutton, $top],
-text => 'Yellow',
-value => 'yellow')->pack(
-side => 'top',
-anchor => 'w');
$wb[3] = $top->Radiobutton(
-variable => \$color,
-command => [\&cb_rbutton, $top],
-text => 'Red',
-value => 'red')->pack(
-side => 'top',
-anchor => 'w');
$wb[4] = $top->Radiobutton(
-variable => \$color,
-command => [\&cb_rbutton, $top],
-text => 'White',
-value => 'white')->pack(
-side => 'top',
-anchor => 'w');
Tk::MainLoop();
sub cb_rbutton {
my $rb = shift;
print "$color is on\n";
return;
}
| [reply] [d/l] |
| [reply] |