 2008/05/16
|
Last update 1999/02/20
TPJ: Issue_07_Tk
- butbreak
- butclass
- butinst
- buttags1
- buttags2
- keysym
- votext
- More Samples on Tk
Download butbreak
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# butbreak - short circuit the bindtags search using break().
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
my $noisy_button = $mw->Button(qw/-text NoisyButton -command/ =>\
|
|
|
|
sub {print "You invoked the <ButtonRelease-1> callback!\n"})\
|
|
->grid;
|
|
$noisy_button->bind('<ButtonRelease-1>' => [\&beep, 1]);
|
|
$noisy_button->bind('<ButtonRelease-2>' => [\&beep, 2]);
|
|
$noisy_button->bind('<ButtonRelease-3>' => [\&beep, 3]);
|
|
my(@tags) = $noisy_button->bindtags;
|
|
$noisy_button->bindtags([@tags[1, 0, 2, 3]]);
|
|
|
|
MainLoop;
|
|
|
|
sub beep {
|
|
my($button, $count) = @ARG;
|
|
while ($count-- > 0) {
|
|
$button->bell; # ring the bell
|
|
$button->after(250);
|
|
}
|
|
$button->break; # short circuit tag search
|
|
}
|
Download butclass
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# butclass - show Button class bindings.
|
|
use Tk;
|
|
use strict;
|
|
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit);
|
|
my $class = ref $b;
|
|
print "Button \$b is an instance of class $class.\n" .
|
|
"This class has bindings for these events:\n\n";
|
|
print $b->bind($class), "\n";
|
Download butinst
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# butinst - show a button's instance bindings.
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
my $noisy_button = $mw->Button(qw/-text NoisyButton -command/ =>\
|
|
|
|
sub {print "You invoked the <ButtonRelease-1> callback!\n"})\
|
|
->grid;
|
|
$noisy_button->bind('<ButtonRelease-2>' => [\&beep, 2]);
|
|
$noisy_button->bind('<ButtonRelease-3>' => [\&beep, 3]);
|
|
my $class = ref $noisy_button;
|
|
print "Button \$noisy_button is an instance of class $class.\n" .
|
|
"This button has class bindings identical to our button\n" .
|
|
"\$b, plus additional instance bindings for these events:\n\n";
|
|
print $noisy_button->bind, "\n";
|
|
MainLoop;
|
|
|
|
sub beep {
|
|
my($button, $count) = @ARG;
|
|
while ($count-- > 0) {
|
|
$button->bell; # ring the bell
|
|
$button->after(250);
|
|
}
|
|
}
|
|
|
Download buttags1
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# buttags1 - show a button's binding tag list.
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
my $noisy_button = $mw->Button(qw/-text NoisyButton/);
|
|
print "Button \$noisy_button has this default list of binding tags:\n\\
|
|
n";
|
|
my(@bindtags) = $noisy_button->bindtags;
|
|
foreach my $tag (@bindtags) {
|
|
print "binding tag = '$tag'\n";
|
|
}
|
Download buttags2
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# buttags2 - show a button's tags and every tag's bindings.
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
my $noisy_button = $mw->Button(qw/-text NoisyButton -command/ =>\
|
|
|
|
sub {print "You invoked two <ButtonRelease-1> callbacks!\n"}\
|
|
)->grid;
|
|
$noisy_button->bind('<ButtonRelease-1>' => [\&beep, 1]);
|
|
$noisy_button->bind('<ButtonRelease-2>' => [\&beep, 2]);
|
|
$noisy_button->bind('<ButtonRelease-3>' => [\&beep, 3]);
|
|
my $class = ref $noisy_button;
|
|
print "Button \$noisy_button is an instance of class $class.\n" .
|
|
"This button has class bindings identical to our button\n" .
|
|
"\$b, plus additional instance bindings for these events:\n\n";
|
|
print $noisy_button->bind, "\n";
|
|
|
|
print "\nHere are \$noisy_button's binding tags, and each tag's bindin\
|
|
gs:\n\n";
|
|
foreach my $tag ($noisy_button->bindtags) {
|
|
print " bindtag tag '$tag' has these bindings:\n";
|
|
print " ", $noisy_button->bind($tag), "\n";
|
|
}
|
|
print "\n";
|
|
MainLoop;
|
|
sub beep {
|
|
my($button, $count) = @ARG;
|
|
while ($count-- > 0) {
|
|
$button->bell; # ring the bell
|
|
$button->after(250);
|
|
}
|
|
}
|
Download keysym
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# keysym - print keyboard character keysysms and the cursor's position\
|
|
.
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
$mw->Label(-text => 'Type a character to see its keysym.')->g\
|
|
rid;
|
|
$mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
$mw->bind('<Key>' => \&print_keysym);
|
|
|
|
MainLoop;
|
|
|
|
sub print_keysym {
|
|
|
|
my($widget) = @ARG;
|
|
my $e = $widget->XEvent; # get reference to X11 event st\
|
|
ructure
|
|
my($keysym_text, $keysym_decimal) = ($e->K, $e->N);
|
|
my($X, $Y, $x, $y) = ($e->X, $e->Y, $e->x, $e->y);
|
|
print "Character = $keysym_decimal, keysym = $keysym_text" .
|
|
" at abs=($X,$Y), rel=($x,$y).\n";
|
|
} # end print_keysym
|
Download votext
|
#!/usr/local/bin/perl -w
|
|
#
|
|
# votext - "view only" Text.
|
|
use English;
|
|
use Tk;
|
|
use strict;
|
|
my $mw = MainWindow->new;
|
|
my $b = $mw->Button(qw/-text Quit -command/ => \&exit)->grid;
|
|
my $t = $mw->Text->grid;
|
|
$t->insert(qw/end HelloWorld/);
|
|
$t->bindtags(undef);
|
|
MainLoop;
|
| Issue_07_Tk8. More Samples on Tk
|

Last update 1999/02/20 
All Rights Reserved - (C) 1997 - 2008 by The Labs.Com |