#!/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; }