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

Dear bretheren, I'm am asking you help because I have this #$!%&** client (oops, need to do more prayers now) who does not like the gauges Tk::Gauge provides. He is able to use printscreen and photoshop and he found some very flashy dials and he is making me do all that I can to use these awful things. My question is. If I save this dial to like a png or gif, how can I use the Tk::Gauge gauge to be placed over it and be transparent so that the needle moves while the picture underneath shows. Or should I use some other module. Canvas? Or gd with tk, or what?
#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Gauge; #use Tk::Canvas; use utf8; my $mw = MainWindow->new; $mw->geometry("600x400"); $mw->configure( -background=>'black' ); $mw->title("map voltmeter"); $mw->optionAdd("*font", "*utf-8"); my $Vdc; $Vdc = 125; my $voltmeter = $mw->Gauge( -highlightbackground => 'black', -highlightcolor => 'black', -highlightthickness => 0, -background => 'black', -start => -180, -extent => -180, -style => 'arc',#'pieslice', -margin => '35', -outlinewidth => 3, -outline => '#10f0f0', -from => 90, -to => 150, -huboutline => '#10f0f0', -hubcolor => '#688898', -hubradius => 7, -hubplace => 'overneedle', -majortickcolor => '#10f0f0', -majortickthickness => 3, -majortickinterval => 10, -minortickinterval => '2', -minortickthickness => 3, -minortickcolor => '#10f0f0', -majorticklabelscale => 10.0 / 100.0, #12.0 / 60.0, -bands => [ { -tag=>'fatred', -arccolor => 'orangered2', -minimum => 140 +, -maximum => 150, -bandwidth => 9, }, ], -bandwidth => 9, -needles => [ { -arrowshape => [ 6, 6, 0 ], -color => 'orangered2', -command => undef, -command => undef, -format => '%d', #-radius => 206, -tag => '', #-titlecolor => 'blue', #-titlefont => 'Helvetica-42', -radius => 190, -variable => \$Vdc, -showvalue => 0, -width => 3, }, ] , -needlepad => 25, )->place(-x => 50, -y => 50); my $Vdc_lcd; #my $label_text = "&#1052;&#1040;&#1055; SIN\n&#1069;&#1053;&#1045;&#1 +056;&#1045;&#1056;&#1043;&#1048;&#1071;"; $mw->Label(-text => '&#1052;&#1040;&#1055; SIN', -font => [-family => 'nimbus sans l', -size => '12', -weight => 'b +old'], -foreground=> '#688898', -background => 'black', )->place( -x => 263, -y => 210 ); $mw->Label( -text => '&#1069;&#1085;&#1077;&#1088;&#1075;&#1080;&#1103;', -font => [-family => 'nimbus sans l', -size => '11', -weight => 'b +old'], -foreground=> '#688898', -background => 'black', )->place( -x => 266, -y => 245 ); $mw->Label( -textvariable => \$Vdc_lcd, -font => ['Helvetica','20'], -foreground=> '#10f0f0', -background => 'black')->place(-x => 5, -y => 5); #$mw -> repeat(500, sub{&movement}); $mw -> repeat(500, sub{&movement}); MainLoop; sub movement { my $range = 10; my $random_number = int(rand($range)); if ($random_number >= 5){ $Vdc++; } else { $Vdc--; } $Vdc = 125 if ($Vdc >=150 || $Vdc <=1); #for gauge purposes $Vdc_lcd = $Vdc/10; $Vdc_lcd = sprintf("%2.1f", $Vdc_lcd); $Vdc_lcd = $Vdc_lcd.' B'; }

Replies are listed 'Best First'.
Re: client wants a pretty gauge from Tk::Gauge
by Sinistral (Monsignor) on May 31, 2011 at 20:18 UTC

    I know you would probably want something that's more "native" for your solution, but Google has a Image Charts library where you would send a GET HTTP request and receive the binary image data back. They also have a next generation Visualization / Charts library, but that would be harder to incorporate into a desktop application, since it relies on JavaScript.

      Thank you! You know, I just figured it out an hour ago! I'm using canvas and putting the image of the gauge in my script via a base64 encode. It's somewhat huge, but here it goes:

        Nicely done. For what it's worth, Tk::Zinc, is an improved canvas that will let you use semi-transparency, matrix rotations, etc. You can have semi-transparent gradients of color, which make things look really professional, like simulated backlighting to the guage, etc. If you are interested, see the Zinc demo, or here is a simple example.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh