Converting Screen Distances

If you prefer to use inches for screen distance but you want to print out pixels, you can use the pixels method to convert any valid screen distance string into a pixel value; for example:

$pixels = $widget->pixels("2i");    # What is 2 inches in pixels?
$pixels = $widget->pixels("2m");    # What is 2 millimeters in pixels?

The pixelsmethod rounds to the nearest whole pixel. You can get a fractional pixel result by using fpixels:

$pixels = $widget->fpixels("2i");    # What is 2 inches in pixels?
$pixels = $widget->fpixels("2m");    # What is 2 millimeters in pixels?

Get Mastering Perl/Tk now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.