Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: how to write a vertical TK Entry?

by tybalt89 (Monsignor)
on Mar 08, 2020 at 18:13 UTC ( [id://11113979]=note: print w/replies, xml ) Need Help??


in reply to how to write a vertical TK Entry?

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11113979]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-29 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found