115ce Short Perl/Tk example - Perl Programming
Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Short Perl/Tk example

Posted by admin (Graham Ellis), 21 September 2002
I've just added the flollowing to s short section of notes on Perl/Tk; thought you might like to share it. I really like Tk, by the way - do have a look at it. The one limitation is on web appliactions - what a pity it doesn't run in the browser!

Quoting the new notes:

There are whole books on Tk; this text gives you just a flavour. Here's a final example for now which provides a GUI front end to a web access log file.   Simply put in the name of a host computer in the text box, and your label will be altered to report on the number of times that host accessed the server during the time logged in the file access_log.

Code:
#!/usr/bin/perl

use Tk;

my $window = MainWindow->new;
$window->title("Host Access Report");
($lab = $window->Label(-text => "Results go here"))->pack;
$window->Entry(-textvariable => \$nnn )->pack;
$window->Button(-text => "Go", -command => \&but )->pack;
$window->Button(-text => "This is the quit button ", -command => \&finito )->pack;
MainLoop;

#########################################################

sub but {
open (FH,"access_log");
$xxx = grep(/^$nnn /,<FH>);
$lab -> configure(-text => "$nnn called in $xxx times");
$nnn = "";
close FH;
}

sub finito{
exit;
}


-textvariable is worth some comment.  Rather than read back a value from a user input box (that can be done too!), we have chosen to have the variable $nnn's current value "automatically reflected" in the entry box.  Very easy coding, and any time the variable is changed it's visible presence on the display also changes.

You'll see even in this simple example how Tk can be used to generate  an easy interface to your system for users who aren't happy with a  command line interface.




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2013: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho
0