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

This is the last time I'm asking this, yet agian, sorry. I'm on Linux for about 10 years now, Gnome 2 (and will never go Gnome 3 cause it's awful). Here, my radiobutton widget looks like diamons

<*>

when as on msWin32 platform they look like a circle within a circle

(*)

The tragic part of my story is that my boss, who knows very little about Linux and Gnome and thinks that I'm pulling his leg about all this nonsence likes the "diamond" look of radiobuttons so much, that he constantly asks me on implementing them. Hence, Is there a way to make Tk::Perl look on windows exactly the way it looks on Linux? Or at least make the Radiobutton look like a diamond? Thank you, and sorry about this sillyiest of questions!

Replies are listed 'Best First'.
Re: Perl::Tk radiobutton yet one more time
by zentara (Cardinal) on Sep 22, 2011 at 10:18 UTC
    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; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: Perl::Tk radiobutton yet one more time
by Anonymous Monk on Sep 22, 2011 at 09:10 UTC
Re: Perl::Tk radiobutton yet one more time
by Khen1950fx (Canon) on Sep 22, 2011 at 08:49 UTC
    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; }

      This should get you up and running....

      And that extract from i>widget - Demonstration of Perl/Tk widgets shows circles on linux/gnome2 and not diamonds?

Re: Perl::Tk radiobutton yet one more time
by zentara (Cardinal) on Sep 22, 2011 at 20:08 UTC