O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Widget Position

The methods in this section all deal with the position of a widget.

Position Relative to the Root Window

To determine which widget is at the point (x, y), use the containing method:

$which = $widget->containing($x, $y);

The $x and $y coordinates must be relative to the root window (or on a Microsoft Windows system, the desktop). An empty string is returned if there is no widget found at those coordinates. If there are several widgets located at those coordinates, the one closest to the front is returned.

Coordinates Relative to the Parent

You can get the coordinates of the upper-left corner of a widget by using the x and ymethods. The coordinates they return are relative to the parent of the widget:

$x = $widget->x;
$y = $widget->y;

Coordinates Relative to the Root Window

To get the coordinates relative to the root window, use rootx and rooty on the widget:

$x = $widget->rootx;
$y = $widget->rooty;

The coordinates refer to the upper-left corner of the widget.

Virtual Desktop Coordinates

If you have a virtual desktop, there are special methods that give coordinates relative to the virtual desktop. Virtual desktops are very common on the X Window System (such as the fvwm and tvtwm window managers), but they exist on Microsoft Windows as well.

To determine the height and width of the virtual desktop, use the vrootheight and vrootwidthmethods:

$height = $widget->vrootheight;
$width = $widget->vrootwidth;

To get the coordinates of the widget’s upper-left corner ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required