~ubuntu-branches/ubuntu/gutsy/horae/gutsy

« back to all changes in this revision

Viewing changes to 0CPAN/Tie-Watch-1.2/examples/tktie

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2006-12-28 12:36:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061228123648-9xnjr76wfthd92cq
Tags: 064-1
New upstream release, dropped dependency on libtk-filedialog-perl.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/local/bin/perl -w
2
 
#
3
 
# Show how to set a watchpoint on a Tk Entry variable.  Using this technique
4
 
# you can do data verification on the user's input.  SOL
5
 
 
6
 
use Tk;
7
 
use Tie::Watch;
8
 
 
9
 
my $MW = MainWindow->new;
10
 
my $foo='cow';
11
 
my $e = $MW->Entry(-textvariable => \$foo)->pack;
12
 
$e->icursor('end');
13
 
$e->focus;
14
 
 
15
 
sub store_callback {
16
 
    print "In store_callback, self=$_[0], new_value=$_[1].\n";
17
 
    $_[0]->Store($_[1]);
18
 
}
19
 
my $w = Tie::Watch->new(-variable => \$foo, -store => \&store_callback);
20
 
 
21
 
my $u = $MW->Button(-text => 'UnWatch $foo', -command => sub {
22
 
    $w->Unwatch;
23
 
    print "Unwatch() value=$foo.\n";
24
 
})->pack;
25
 
 
26
 
my $l = $MW->Button(-text => 'Quit', -command => sub {
27
 
    print "Final value=$foo.\n";
28
 
    exit;
29
 
})->pack;
30
 
 
31
 
MainLoop;