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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho