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


In reply to Re: Perl Tk : How to adjust labels width in textarea with every screen resolution. by Anonymous Monk
in thread Perl Tk : How to adjust labels width in textarea with every screen resolution. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.