in reply to Re^3: Perl Tk : How to adjust labels width in textarea with every screen resolution.
in thread Perl Tk : How to adjust labels width in textarea with every screen resolution.

Hi, This doesn't seem working for me (for recommended screen resolution 1920*1080), "ADDRESSS" seems going on next line as width of the ADDRESS is more than it should be.

Me neither.

I've read it three times now.

Its not working for me.

Maybe you can try something besides saying it doesn't work for you.

Look at the numbers or something.

Make a connection between the characters and pixels.

  • Comment on Re^4: Perl Tk : How to adjust labels width in textarea with every screen resolution.

Replies are listed 'Best First'.
Re^5: Perl Tk : How to adjust labels width in textarea with every screen resolution.
by Anonymous Monk on Dec 05, 2019 at 04:33 UTC

    Hi, Yes I definitely need to try out something else.
    Thank you

      #!/usr/bin/perl -- #!D:\Strawberry\perl\bin\perl.exe ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while for " +-otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use diagnostics; use Tk; use Tk::ROText; my $mw = tkinit( -background => '#990033' ); my $sw = $mw->screenwidth; #1920 my $sh = $mw->screenheight; #1080 my $frame_width = $sw * 0.108; print "\$sw : $sw\n\$frame_width : $frame_width\n"; my $frame = $mw->Frame(); my $pane = $frame->Frame()->pack(qw/-expand 0 -fill x /); my $txt = $frame->Scrolled( 'ROText', -width => $frame_width, -height => 22, -font => "{sans serif} 10", -background => 'lightgray' ); Enter_labels_in_textarea( $pane,, enter_values( $frame_width ) ); $txt->insert('end', "1\n2\n3\n4\n".rand."\n" ); $frame->pack(qw/ -expand 1 -fill both /); $txt->pack(qw/ -expand 1 -fill both /); $mw->WidgetDump; MainLoop(); exit( 0 ); sub Enter_labels_in_textarea { my( $rotext, $enter_values ) = @_; foreach my $val (@$enter_values) { my( $text, %options ) = @$val; #~ delete $options{-width}; my $label = $rotext->Label( -foreground => 'white', -font => 10, -height => 1, -cursor => 'leftbutton', -relief => 'raised', -justify => 'left', -text => $text, %options, ); #~ $rotext->windowCreate( 'end', -window => $label , ); $label->pack(qw/ -expand 1 -fill x -side left -anchor n /); print "$label $text @{[%options]}\n"; } } sub enter_values { my( $frame_width ) = @_; my $chars = $frame_width / 11; my @values = ( [ 1, -background => 'navyblue', ], [ 'NAME', -background => '#990033', ], [ 'AGE', -background => '#990033', ], [ 'PROFESSION', -background => '#990033', ], [ 'CONTACT', -background => '#FF0000', ], [ 'ADDRESS', -background => 'darkgreen', ], ); @values = map { my $len = length($_->[0]); if( $len > 5 ){ $len += 8; } else { $len += 2; } push @$_, -width => $len; $_; } @values; return \@values; } __END__

        Hi,

        This seems working for me, though i need to modify it a bit as width of lables would be dynamic.

        Thank you. Cheers !!!

        Update : not width of the labels but value of the labels would be dynamic could have different lengths.