Out of half curiosity, half boredom, and half fun, I tried to build a (very incomplete) vertical entry
from a Label widget using newlines to get a vertical display.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $text = 'Vertical';
my $entry = 'Entry';
my $mw = MainWindow->new;
$mw->geometry( '+600+200' );
$mw->Label(-text => "Two\nVerticalEntry\nWidgets", -fg => 'blue',
-font => 'courierbold 20',)->pack;
my $middle = $mw->Frame->pack;
verticalentry( $middle, \$text, 12, sub {print "left text: $text\n"},
-side => 'left' );
my $updateright = verticalentry( $middle, \$entry, 12,
sub {print "right text: $entry\n"}, -side => 'right' );
$middle->Frame(-width => 30)->pack;
$mw->Button(-text => 'Exit', -command => sub {$mw->destroy},
)->pack( -side => 'bottom', -fill => 'x' );
$mw->Button(-text => 'Clear Right', -command => sub {$updateright->(''
+)},
)->pack( -side => 'bottom', -fill => 'x' );
$mw->repeat( 400, sub { -M $0 < 0 and $mw->destroy } ); # file saved a
+fter run
MainLoop;
-M $0 < 0 and exec $0; # restart on editor save :)
sub verticalentry
{
my ($parent, $textref, $length, $command, @packargs) = @_;
my $edit = $parent->Label(-width => 1,
-relief => 'sunken', -borderwidth => 3,
-font => 'courierbold 30')->pack( @packargs );
my $update = sub
{
@_ and $$textref = shift;
$edit->configure(-text => join "\n",
split //, substr $$textref . ' ' x $length, 0, $length);
};
$update->();
$edit->bind('<Enter>' => sub { $edit->focus } );
$edit->bind('<Key>' => sub {
my $key = $_[0]->XEvent->A;
use Data::Dump 'dd'; dd $key;
if( $key =~ /^[ -~]$/ )
{
length $$textref < $length and $$textref .= $key;
}
elsif( $key eq "\b" )
{
chop $$textref;
}
elsif( $key eq "\r" )
{
$command->();
}
$update->();
} );
return $update;
}
If nothing else, it shows a way to get a vertical column of text :)
This example has two independent vertical entries just so I could be sure
all the closure stuff worked correctly.