or advice on my little program, i'd be glad to hear it.

Since you asked, rather than using a lot of similar variable names like $row0, $row1 ,$row2 etc consider using an array. For example

my @col = (40,$center-35,$center+30,$breed-40); my @row = (20,40,60,80,90,110);

a few more changes (mainly style) here

#!perl use strict; use warnings; use 5.010; use Tk; printf "Tk::VERSION %s\n",$Tk::VERSION; # Declarations my $breed = 400; # width my $hoog = 200; # height my $netspdx = 1; my $netspdy = 0; my $netuse = 0.05; my $fsizex = 3; my $fsizey = 0; my $mw = new MainWindow( -height => $hoog, -width => $breed, -title => 'Downloadtime estimator' ); init(); MainLoop; sub init { my $center = $breed/2; my @col = (40,$center-35,$center+30,$breed-40); my @row = (20,40,60,80,90,110); my @speed = ( undef, ['Gb',1000000000], ['Mb',1000000], ['kb',1000], ); my @button = (); # Row 0 my $y = $row[0]; $mw->Label(-text=>"Fill in the fields and check the right boxes") ->place( -x=>$center, -y=>$y, -anchor=>'center' ); # Row 1 $y = $row[1]; $mw->Label(-text=>"Network speed") ->place( -x=>$col[0], -y=>$y, -anchor=>'w' ); $mw->Entry( -justify=>'right',-textvariable=> \$netspdx, -width=>5 ) ->place( -x=>$center, -y=>$y, -anchor=>'center' ); my $x = $col[2]; for my $i (1..3){ $button[$i] = $mw-> Radiobutton( -variable=> \$netspdy, -text => $speed[$i][0], -value => $speed[$i][1]) -> place( -x =>$x, -y=>$y, -anchor=>'w' ); $x += 50; } $button[1]->select(); # Row 2 $y = $row[2]; $mw->Label( -text=>"Avg network use in %" ) ->place( -x=>$col[0], -y=>$y, -anchor=>'w' ); $mw->Entry( -textvariable=> \$netuse, -width => 5, -justify => 'righ +t', ) ->place( -x=>$center, -y=>$y, -anchor=>'center' ); # Row 3 $y = $row[3]; $mw->Label( -text=>"File size" ) + ->place( -x=>$col[0], -y=>$y, -anchor=>'w' ); $mw->Entry( -textvariable=> \$fsizex, -width => 5, -justify=>'right' ) ->place( -x=>$center, -y=>$y, -anchor=>'center' ); $x = $col[2]; for my $i (1..3){ $button[$i+3] = $mw-> Radiobutton( -variable=> \$fsizey, -text => uc $speed[$i][0], -value => $speed[$i][1]) ->place( -x=>$x, -y=>$y, -anchor=>'w' ); $x += 50; } $button[4]->select(); # Row 5 $y = $row[5]; $mw->Label( -text=>"Estimated time" ) ->place( -x=>$col[0], -y=>$y, -anchor=>'w' ); my $result = $mw->Label( -text=>'' ) ->place( -x=>$center, -y=>$y, -anchor=>'center' ); my $units = $mw->Label( -text=>'' ) ->place( -x=>$col[2], -y=>$y, -anchor=>'w' ); # Row 6 $y = $hoog-50; # OK button $mw->Button( -text => "Okay", -width => 10, -command => [\&Calc,$result,$units] ) ->place( -x=>$center-100, -y=>$y ); # Exit button $mw->Button(-text => "Exit", -width => 10, -command => sub { exit }) ->place( -x=>$center+100, -y=>$y ); } sub Calc { my ($result,$units) = @_; my $time = $fsizex*$fsizey / ($netspdx*$netspdy/100*$netuse); my $text = 'Seconds'; if ($time > 60){ $time = $time / 60; $text = 'Minutes'; if ($time > 60){ $time = $time / 60; $text = 'Hours'; if ($time > 24){ $time = $time / 24; $text = 'Days'; } }; } $units->configure(-text=>$text); $result->configure(-text=>sprintf "%.2f",$time); };
poj

In reply to Re^4: Tk : Entry widget-Strange behaviour with decimals by poj
in thread Tk : Entry widget-Strange behaviour with decimals by Caerwyn1955

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.