use Tk; use Scalar::Util qw{looks_like_number}; my ($feet, $metres) = (q{}, q{}); my $mw = MainWindow->new(-title => q{Feet to Metres}); my $f = $mw->Frame() ->grid(-padx => 12, -pady => 3, -sticky => q{nsew}); my %pad = (-padx => 5, -pady => 5); my $feet_E = $f->Entry(-textvariable => \$feet, -width => 7) ->grid(-row => 0, -column => 1, -sticky => q{we}, %pad); $f->Label(-text => q{feet}) ->grid(-row => 0, -column => 2, -sticky => q{w}, %pad); $f->Label(-text => q{is equivalent to}) ->grid(-row => 1, -column => 0, -sticky => q{e}, %pad); $f->Label(-textvariable => \$metres) ->grid(-row => 1, -column => 1, -sticky => q{we}, %pad); $f->Label(-text => q{metres}) ->grid(-row => 1, -column => 2, -sticky => q{w}, %pad); my $calc_B = $f->Button(-text => q{Calculate}, -command => sub { $metres = looks_like_number($feet) ? int(0.3048 * $feet * 10000.0 + 0.5) / 10000.0 : q{}; })->grid(-row => 2, -column => 2, -sticky => q{w}, %pad); $feet_E->focus(); $mw->bind(q{} => sub {$calc_B->invoke()}); MainLoop;