A quick Tk Application

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

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...

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); }

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  => '',
         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 Penrose
Welcome to the Digital Dimension
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 
Version: GnuPG v1.2.3 (Darwin)


More information about the Melbourne-pm mailing list