Creating a frame widget

The frame widget is used as a container for other widgets. Although it works in and of itself, it accepts no input from the user nor does it provide feedback. It simplifies the layout of complex screens and adds to the appearance of the final product. To add a widget to a frame, we use the following syntax:


% 1 frame .f
% 2 button .f.b -text "My Button"

The naming hierarchy in Tcl is such that we prepend the name of the container. In this case, a frame is prepended to the button to instruct the interpreter that the button is contained within a container. A container can be a window, top level, canvas, or frame, as in the previous example.

The keywords are described in the Tk main pages as follows:

Standard keywords

Interpretation

-borderwidth or -bd

Specifies a non-negative value indicating the width of the border to draw around the outside of the window.

-cursor

Specifies the mouse cursor to be used for the window.

-highlightbackground

Specifies the color to display in the traversal highlight region when the window does not have the input focus.

-highlightcolor

Specifies the color to use for the traversal highlight rectangle that is drawn around the window when it has the input focus.

-highlightthickness

Specifies a non-negative value indicating the width of the highlight rectangle to draw around the outside of the window.

-padx

Specifies a non-negative value indicating how much extra space to request for the window in the X-direction.

-pady

Specifies a non-negative value indicating how much extra space to request for the window in the Y-direction.

-relief

Specifies the 3D effect desired for the window. Acceptable values are raised, sunken, flat, ridge, solid, and groove.

-takefocus

Determines whether or not the window accepts the focus during keyboard traversal.

-background

Specifies the background color to use when drawing.

-class

Specifies a class for the window.

-colormap

Specifies a color map to use for the window.

-container

The value must be a Boolean value. If true, it means that this window will be used as a container in which some other application will be embedded (for example, a Tk top level can be embedded using the -use keyword). The window will support the appropriate window manager protocols for things such as geometry requests. The window should not have any children of its own in this application. This keyword may not be changed with the configure window command.

-height

Specifies the desired height for the window.

-visual

Specifies visual information for the new window.

-width

Specifies the desired width for the window.

How to do it…

In the following example, we again will create a frame widget with defined keywords to control its appearance. Enter the following command:


1 % frame .f -width 160 -height 90 -borderwidth 5 -relief raised
.f
2 % pack .f

At this point, your window should look like the following:

How to do it…

How it works…

Based on the keywords provided, we have created a frame widget named .f, a width of 160 pixels, a height of 90 pixels, a border width of 5 pixels, and a raised border relief.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.159.178