#!/user/bin/perl use warnings; use strict; use Tk; use Tk::Font; my $mw = MainWindow->new(); # window instance $mw->fontCreate('josh', -family=>'Arial', -size=>20); # give the font instance an arbitrary name 'josh'; specify font family and size here my $sentence = "This is my sample sentence to measure."; my $length = $mw->fontMeasure('josh', $sentence); # use the arbitrary font name here with the text to measure print "Your sample sentence is $length pixels long in the specified font and size.\n";