A quick Tk Application

Scott Penrose scottp at dd.com.au
Thu Mar 25 15:02:08 CST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Dudes.

I have a favour to ask if someone has time please. I am no Tk expert 
and have run out of time to do a quick demonstration. I was wondering 
if someone could write up a very very small Tk app for me for the VTR 
conference tomorrow.

What I am looking for is a simple application that:

	* Has two Text Box - each 5 characters wide
	* Has a button (Clear) to clear those
	* Has a button (Exit) to exit
	* Has each of the two Text Box values 'tied' so that I can trigger 
when they change.

Then on change of the text if they could call "sendit($a, $b);" - it 
would be finished.

Here is my attempt...

#!/usr/bin/perl
use strict;
use warnings;
use Tk;

my $top = MainWindow->new;
$top->Button(-text => "Exit", -command => sub { exit 0; })->pack;
$top->Button(-text => "Clear", -command => sub { })->pack;
$top->Entry(-width => 5)->pack;	# sub { sendit(1, $val); }
$top->Entry(-width => 5)->pack;	# sub { sendit(2, $val); }
MainLoop;

sub sendit {
	my ($line, $text) = @_;
	# XXX Call send code here.
}

The purpose of it is to demonstrate both a little tiny Tk script (I 
don't do any Tk programming and it still only took me 5 minutes to 
learn how to do the above) - and a network connection to another daemon 
controlling a big LED Display.

The actual send code is:

my $sock = IO::Socket::INET->new(
         PeerPort  => 2000,
         PeerAddr  => '10.0.1.16',
         Proto     => 'tcp',
) or die "Can't bind : $@\n";
$sock->send("$line $text\n");

My main problem is that I don't know how to trigger the call to the 
sendit on change of text. If that is too hard, press button will be 
just as good.

Scott
- -- 
Scott Penrose
Welcome to the Digital Dimension
http://www.dd.com.au/
scottp at dd.com.au

Dismaimer: Contents of this mail and signature are bound to change 
randomly. Whilst every attempt has been made to control said 
randomness, the author wishes to remain blameless for the number of 
eggs that damn chicken laid. Oh and I don't want to hear about 
butterflies either.

Please do not send me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQFAY0jUDCFCcmAm26YRAsL1AJ9C25tMK/cVkyzXjv8GdDz9WVQsuwCfZoWI
W2F6epKBa3TqJ0cDlodFof4=
=EVwU
-----END PGP SIGNATURE-----




More information about the Melbourne-pm mailing list