12.1. Creating a Frame

Use the parent widget of the frame to invoke the Frame() method:

$frame = $parent->Frame( [ option => value, ... ])->pack();

The $parent can be a MainWindow, a toplevel, or another frame widget.[2] After the frame is created, it can become a parent to other widgets. You must have created the frame but not necessarily packed it on the screen for it to be the parent of other widgets. Keep in mind that, even if you pack other widgets inside your frame, if you don't pack the frame as well, the other widgets won't show on the screen.

[2] Technically, any widget can be a parent of another widget, but I like to make my life easier when it comes to placing the widget inside the window. If I made a frame the child of a $button, I wouldn't be able to pack it inside the button. I would then have to use the -in option with pack, confusing myself even further. Keep it simple, and you'll be much happier.

Just as with all the other widgets in Perl/Tk, the options specified in the Frame method will change how the frame looks inside the window. There are few options available with the frame widget, and they aren't complicated at all. This section covers all the options and what they do.

-background => color

Sets the color of the frame's background area (there is no foreground area).

-borderwidth => amount

Sets the width of the frame's edges. Default is 0.

-class =>classname

Indicates the class associated with the frame in the option database. This option can actually be ...

Get Learning 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.