Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl Tk : How to adjust labels width in textarea with every screen resolution.

by Anonymous Monk
on Dec 02, 2019 at 15:53 UTC ( [id://11109546]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have Tk textarea with embedded Labels on each line (5 labels on each line), all labels have been calculated using screenwidth of the screen.
While all lables are fitting very well in the textarea with current resolution i.e.(1280*800) with one laptop, but breaks when run the same application, on laptop with higher i.e. resolution (1920*1080), even when i adjust resolution to (1280*800) on that laptop.

When i say breaks it means its running over on next line, because width of the labels are more than it should be.

Note that i have set application geometry with full screen width and full screen height, which means application will cover total screen of the laptop/desktop.
How to set up the width of the labels in given textarea which would apply to every resolution.

Thank you

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

Replies are listed 'Best First'.
Re: Perl Tk : How to adjust labels width in textarea with every screen resolution.
by haukex (Archbishop) on Dec 02, 2019 at 18:04 UTC

    Please see SSCCE: You're likely to get more and better responses if you can provide a short (10-20 lines) runnable piece of code that demonstrates the problem, so that people can easily reproduce the problem for themselves.

Re: Perl Tk : How to adjust labels width in textarea with every screen resolution.
by Anonymous Monk on Dec 03, 2019 at 02:16 UTC

    all labels have been calculated using screenwidth of the screen..... How to set up the width of the labels in given textarea which would apply to every resolution.

    Weird question

    In that , how can you calculate labels using screenwidth, then wonder how to set/configure labels width

    I dont understand what you're missing

Re: Perl Tk : How to adjust labels width in textarea with every screen resolution.
by Anonymous Monk on Dec 03, 2019 at 16:49 UTC

    Hi Monks,

    Below is the sample code which depicts what I am trying to achieve,

    on my desktop with resolution (1920*1080), all labels are fitting well in the line, but when I try it on laptop with different resolution, labels could go on the next line due to width changes or they will be having less width than it should be.

    #!D:\Strawberry\perl\bin\perl.exe use strict; use Tk; use Tk::ROText; my($cnt, $w0,$w1,$w2,$w3,$w4,$w5); # Main Window my $mw = new MainWindow(-background =>'#990033'); ###FOCUS ON MAIN WINDOW $mw->focus(); my $sw = $mw->screenwidth; #1920 my $sh = $mw->screenheight; #1080 my @enter_values = (1,'NAME','AGE','PROFESSION','CONTACT','ADDRESS'); ###################################################################### ##Text Area my $textarea_width = $sw*0.108; print "\$sw : $sw\n\$textarea_width : $textarea_width\n"; my $textarea = $mw->Frame(); my $txt = $textarea->ROText(-width=>$textarea_width,-height=>22,-font= +>"{sans serif} 10", -background => 'lightgray'); my $srl_y = $textarea->Scrollbar(-orient=>'v',-command=>[yview=>$txt]) +; my $srl_x = $textarea->Scrollbar(-orient=>'h',-command=>[xview=>$txt]) +; $txt-> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>['set',$srl_x]); &Enter_labels_in_textarea; ###Text Area $textarea->grid; $txt->grid(-row=>9,-column=>1); $srl_y->grid(-row=>9,-column=>2,-sticky=>"ns"); $srl_x->grid(-row=>10,-column=>1,-sticky=>"ew"); MainLoop; sub Enter_labels_in_textarea { $cnt = 0; foreach my $val(@enter_values){ ##print "\$val => $val\n\n"; if($cnt == 0){ $w0 = $txt->Label(-text =>"$val",-foreground =>'white',-background =>' +navyblue',-font=>10, -width=>($textarea_width*0.025), -height=>1, -cu +rsor => 'leftbutton', -relief =>'raised',-justify=>'left'); print "\$w0 : $w0\n"; $txt->windowCreate('end', -window => $w0); } elsif($cnt == 1){ $w1 = $txt->Label(-text =>"$val",-foreground =>'white',-background =>' +#990033',-font=>10, -width=>($textarea_width*0.16), -height=>1, -curs +or => 'leftbutton', -relief =>'raised',-justify=>'left'); $txt->windowCreate('end', -window => $w1); } elsif($cnt == 2){ $w2 = $txt->Label(-text =>"$val",-foreground =>'white',-background =>' +#990033',-font=>10, -width=>($textarea_width*0.10), -height=>1,-relie +f =>'raised',-justify=>'left'); $txt->windowCreate('end', -window => $w2); } elsif($cnt == 3){ $w3 = $txt->Label(-text =>"$val",-foreground =>'white',-background =>' +#990033',-font=>10, -width=>($textarea_width*0.10), -height=>1,-relie +f =>'raised',-justify=>'left'); $txt->windowCreate('end', -window => $w3); } elsif($cnt == 4){ $w4 = $txt->Label(-text =>"$val",-foreground =>'white',-background +=>'#FF0000',-font=>10, -width=>($textarea_width*0.10), -height=>1,-re +lief =>'raised',-cursor => 'leftbutton',-justify=>'left'); $txt->windowCreate('end', -window => $w4); } else { $w5 = $txt->Label(-text =>"$val",-foreground =>'white',-background =>' +darkgreen',-font=>10, -width=>($textarea_width*0.14), -height=>1,-rel +ief =>'raised',-cursor => 'leftbutton',-justify=>'left'); $txt->windowCreate('end', -window => $w5); } $cnt++; } }

    Thank you

      Below is the sample code which depicts what I am trying to achieve,

      Hi

      perlintro, Modern Perl , the future is now :)

      #!/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 $txt = $frame->ROText( my $txt = $frame->Scrolled( 'ROText', -width => $frame_width, -height => 22, -font => "{sans serif} 10", -background => 'lightgray' ); Enter_labels_in_textarea( $txt->Subwidget('scrolled'), enter_values( $frame_width ) ); $txt->insert('end', "\n\n\n\n".rand."\n" ); $frame->pack(qw/ -expand 1 -fill both /); $txt->pack(qw/ -expand 1 -fill both /); #~ $txt->grid( -row => 9, -column => 1 ); #~ $txt-> $mw->WidgetDump; MainLoop(); exit( 0 ); sub Enter_labels_in_textarea { my( $rotext, $enter_values ) = @_; foreach my $val (@$enter_values) { my( $text, @options ) = @$val; my $label = $txt->Label( -foreground => 'white', -font => 10, -height => 1, -cursor => 'leftbutton', -relief => 'raised', -justify => 'left', -text => $text, @options, ); $rotext->windowCreate( 'end', -window => $label , ); print "$label $text @options\n"; } } sub enter_values { my( $frame_width ) = @_; return [ [ 1, -background => 'navyblue', -width => ( $frame_width * ((2+length '1') /100) ) ], [ 'NAME', -background => '#990033', -width => ( $frame_width * 0.16 ), ], [ 'AGE', -background => '#990033', -width => ( $frame_width * ((2+length 'AGE') /100) ), ], [ 'PROFESSION', -background => '#990033', -width => ( $frame_width * ((2+length 'PROFESSION')/100) ), ], [ 'CONTACT', -background => '#FF0000', -width => ( $frame_width * 0.16 ), ], [ 'ADDRESS', -background => 'darkgreen', -width => ( $frame_width * 0.24 ), ], ]; }

        Hi, Thank you for this code, let me check and revert.

        But I am wondering what makes this code to get all the 5 lables on separate line of textarea on each and every resolutions on different machines.

        Regards

        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.

        Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found