Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
This another script that I have written with Perl/Tk as an interface to brian d foy's module Chemistry::Elements Being of an Earth Sciences background I saw this module, thought it was cool, decided to put it to Tk, and see what happened. I still consider this code to be in its "early stages". For right now, you enter the element symbol, click on Find, and if it is a valid element symbol you get the element name and atomic number. It has been a while since I have worked on this one. The goal for the next version is to be able to enter a value into any of the boxes and get appropriate output in the other two.

As always, any input or suggestions for improvement of this code are greatly appreciated. Enjoy and Have Fun!

Learning Is What Makes Life Interesting!


#!/usr/bin/perl -w # use English; use Chemistry::Elements qw(get_name get_Z get_symbol); use Tk; use Tk::DialogBox; use strict; sub convert ; my $MW = MainWindow->new; ### --- Prevents Main Window Resizing $MW->bind('<Configure>' => sub{ my $xe = $MW->XEvent; $MW->maxsize($xe->w, $xe->h); $MW->minsize($xe->w, $xe->h); }); ### --- Main Window Title $MW->title("The Elements"); ### --- Create Button Frame my $button_frame = $MW->Frame(); $button_frame->pack(-side => 'bottom', -expand => '1', -fill = +> 'both'); ### --- Create About Button $button_frame->Button(-text => "About", -foreground => "#007300", -activebackground => "#98FB98", -font => 'Arial', -command => sub { my $dialogA = $MW->DialogBox( -title => "About this program" +, -buttons => [ "OK" ], ); $dialogA->add("Label", -borderwidth => '3', -background => "#FAEBD7", #ANTIQUE WHITE -font => 'bold', -justify => 'left', -relief => 'sunken', #One seriously long text string f +ollows on the next line --> -text => "FOR BEST RESULTS USE: PERL 5 +.6.1 \& Tk 8.0 OR BETTER\nThis program requires use of the perl modul +e Chemistry::Elements.\nVersion 1.0 -- 03\/06\/2001 Original Code +Written by Jay Madigan.\nVersion 1.1 -- 03\/09\/2001 Cleaned up \& + Commented code, implemented use strict;.\nVersion 1.2 -- 03\/10\/ +2001 Added code to prevent Main Window & Dialog Box resizing\r\t + - resized (enlarged) About dialog box font for better readability.\ +nVersion 1.3 -- 05\/26\/2001 Added Error Message Dialog Box for in +valid entries.\nVersion 1.4 -- 08\/19\/2001 Changed all widget fon +ts to Arial.\nVersion 1.4.1 -- 12\/04\/2001 Minor text formatting cha +nges in About Box.\nVersion 1.5 -- 02\/16\/2001 Changed Main Windo +w Title to \"The Elements\".\n*************************************** +*********************************************************\nThis progr +am is freeware and may be modified and\/or redistributed \nunder the +same terms as the GNU public license of PERL. \nNo warranty on this c +ode is assumed or implied. ")->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(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Exit Button my $exit = $button_frame->Button(-text => 'Exit', -foreground => 'red', -activebackground => "#FF9090", -font => 'Arial', -command => sub { exit; }); $exit->pack(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Convert Button my $convert = $button_frame->Button(-text => 'Find', -foreground => "blue", -activebackground => "#ADD8E6", -font => 'Arial', -command => sub { convert; }); $convert->pack(-side => 'right', -expand => '1', -fill => 'both'); ### --- Create Element Atomic Number Frame my $number_frame = $MW->Frame()->pack(-expand => '1', -fill => 'both', + -side => 'bottom'); $number_frame->Label(-text => "Atomic number:", -font => 'Arial')->pac +k(-side => 'left'); my $number_value = $number_frame->Entry(-font => 'Arial', -width => '3 +', -relief => 'sunken')->pack(-side => 'left'); # # ### --- Create Element Name Frame my $name_frame = $MW->Frame()->pack(-expand => '1', -fill => 'both', - +side => 'bottom'); $name_frame->Label(-text => "Element name:", -font => 'Arial')->pack(- +side => 'left'); my $name_value = $name_frame->Entry(-font => 'Arial', -width => '12', +-relief => 'sunken')->pack(-side => 'right'); # # ### --- Create Entry Frame my $entry_frame = $MW->Frame()->pack(-expand => '1', -fill => 'both', +-side => 'bottom'); $entry_frame->Label(-foreground => 'red', -font => 'Arial', -text => " +Enter element symbol:")->pack(-side => 'left'); my $convert_value = $entry_frame->Entry(-highlightbackground => 'red', +-highlightthickness => '1', -font => 'Arial', -width => '3', -relief +=> 'sunken')->pack(-side => 'left'); MainLoop; #### BEGIN SECTION FOR SUBROUTINES ---- sub convert { my $question = $convert_value->get; my $name = get_name($question); my $number = get_Z($question); print "$name\n"; ## generate "sqwauk box" if invalid entry was made ## resulting in null output if(!(defined $name)){ my $dialogW = $MW->DialogBox( -title => "ERROR! Please Try Again +.", -buttons => [ "OK" ], ); $dialogW->add("Label", -text => " \"$question\" is not a valid + entry. ", -font => "Arial", -foreground => "red")->pack; ### --- Prevents Dialog Box Resizing $dialogW->bind('<Configure>' => sub{ my $xeW = $dialogW->XEvent; $dialogW->maxsize($xeW->w, $xeW->h); $dialogW->minsize($xeW->w, $xeW->h); }); $dialogW->Show; } $number_value->delete('0', 'end'); $number_value->insert('0', $number); $name_value->delete('0', 'end'); $name_value->insert('0', $name); }

In reply to Perl/Tk-Chemistry::Elements by PERLscienceman

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (16)
    As of 2014-07-23 16:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (147 votes), past polls