Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Greetings Perl Monks and all others interested in Perl who visit this site. In tinkering around with Perl at home I like to create science related scripts using Tk and other cool related modules that I have discovered. My latest experiment in Perl/Tk is a Weather Forecast Map Grabber. In this script I make use of the modules: Tk, Tk::DialogBox, and LWP::Simple to grab the image from the internet, place it in a sized Tk Window, and provide a little bit of information when you click on the image (that's where the Dialog Box comes in). The Map is a simple forecast map generated by the National Weather Service centered on North America. However, the link can be changed in the code to grab any map or image that you want and display it. Anyway enough said. The code is posted below. Enjoy!

As always, any feedback or suggestions for improvement of the code are greatly appreciated. I am continuously looking for new and cool ways to do things in Perl.


#!/usr/bin/perl -w use strict; use LWP::Simple; use Tk; use Tk::DialogBox; my $url="http://www.hpc.ncep.noaa.gov/noaa/noaa.gif"; my $file="noaa.gif"; my $MW=MainWindow->new(-title=>"NOAA/NWS/NCEP Current U.S. Forecast Ma +p"); ### --- Prevents Main Window Resizing $MW->bind('<Configure>' => sub{ my $xe = $MW->XEvent; $MW->maxsize($xe->w, $xe->h); $MW->minsize($xe->w, $xe->h); }); print "Please Wait...\nAcquiring Image from www.hpc.ncep.noaa.gov .... +\n"; my $status=getstore($url,$file); if ($status==500){ my $exit = $MW->Button(-text => "500-NETWORK ERROR Unable to Commu +nicate with Host\nCheck your Network Connection!\n Click to EXIT", -foreground => 'red', -background => "yellow", -activebackground => "red", -font => 'Arial', -command => sub { exit; }); $exit->pack; MainLoop(); } if ($status==404){ my $exit = $MW->Button(-text => "404-ERROR FILE MISSING\nImage is +Temporarily Unavailable on Server\n Click to EXIT", -foreground => 'red', -background => "yellow", -activebackground => "red", -font => 'Arial', -command => sub { exit; }); $exit->pack; MainLoop(); } print "generating Tk Window ....\n"; my $image = $MW->Photo(-file=>"noaa.gif", -width=>896, -height=>716); $MW->Button(-image=>$image, -width=>896, -height=>716, -command => sub { my $dialogA = $MW->DialogBox( -title => "About This Image", -buttons => [ "OK" ], ); $dialogA->add("Label", -borderwidth => '2', -background => "#FAEBD7", #ANTIQUE WHITE -font => 'bold', -justify => 'left', -relief => 'sunken', -text => "This Image is Produced by:\n + National Weather Service Hydrometeorological Prediction Center\n htt +p://www.hpc.ncep.noaa.gov/ \nThis forecast is updated daily \@ 09:00 +UTC. ")->pack; ### --- Prevents Dialog Box Resizing $dialogA->bind('<Configure>' => sub{ my $xeD = $dialogA->XEvent; $dialogA->maxsize($xeD->w, $xeD->h); $dialogA->minsize($xeD->w, $xeD->h); }); $dialogA->Show; } )->pack; MainLoop(); ############################################# ## TkForecastMap.pl ## version 1.0 -- 07/23/2003 by Jay Madigan ## This program is freeware and may be modified and/or redistributed ## under the same terms as the GNU public license of Perl. ## No warranty on this code is assumed or implied. #############################################

edited by ybiC: balanced <readmore> tags


In reply to Perl/Tk --- Weather Map Grabber by PERLscienceman

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-03-29 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found