programming-examples/perl/GUI/Hide and show control.pl
2019-11-15 12:59:38 +01:00

42 lines
1.2 KiB
Perl

#!/usr/local/bin/perl -w
use Tk;
use strict;
my $str = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789";
my $mw = MainWindow->new;
my $lframe = $mw->Frame->pack(-fill => 'both', -side => 'left', -expand => 1);
my $lb = $lframe->Scrolled(qw/Listbox -scrollbars e -height 3/)->
pack(qw/-fill both -expand 1 -side top/);
$lb->insert('end', sort $mw->fontFamilies);
my $hidebutton = $mw->Button(-text => ">");
$hidebutton->pack(-side => 'left', -fill => 'y');
$hidebutton->configure(
-command => sub {
if ($hidebutton->cget(-text) eq ">") {
$lframe->packForget; $hidebutton->configure(-text => "<")
} else {
$lframe->pack(-before => $hidebutton, -fill => 'both',
-side => 'left', -expand => 1);
$hidebutton->configure(-text => ">");
}
},
-font => "courier 8",
);
my $entry = $mw->Entry(
-textvariable => \$str,
)->pack(-expand => 1, -fill => 'x', -side => 'left');
$lb->bind("<Button>", sub { $entry->configure(-font =>
"{". $lb->get($lb->curselection) . "} 72"); });
MainLoop;
# Causes text to be wrapped around.
sub shift_banner {
my $newstr = substr($str, 1) . substr($str, 0, 1);
$str = $newstr;
}