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

In reply to Re: Perl::Tk radiobutton yet one more time by zentara
in thread Perl::Tk radiobutton yet one more time by pashanoid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.