Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Perl/Tk-Chemistry::Elements

by PERLscienceman (Curate)
on Jul 12, 2003 at 05:19 UTC ( #273597=CUFP: 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); }

Comment on Perl/Tk-Chemistry::Elements
Download Code
Re: Perl/Tk-Chemistry::Elements
by zentara (Archbishop) on Jul 12, 2003 at 15:39 UTC
    Thanks for the link to Chemistry::Elements. I went to cpan and used the Kobes search engine, and it wouldn't find it, but search.cpan.org did. I wonder why?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://273597]
Approved by TStanley
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-11-27 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (183 votes), past polls