| 12.3 Frames, the Archetypal, No-Frills Widgets |
|
|
The frame widget maker is archetypal in the sense that what you can do with it you can do with other kinds of widget makers as well. All built-in widget makers are invoked this way: widget_type_name WIDGET_NAME ?OPTIONS?where widget_type_name is the name of a kind of widget and of the widget maker that creates such a widget. Below in Chapter 15, you see will that the section titles list all the possible widget types. WIDGET_NAME is the pathname of the new widget object as described in The Tk Way of Thinking. ?OPTIONS? is a sequence of zero or more option value pairs. All built-in widget makers return WIDGET_NAME and all of them create an object action family whose name is WIDGET_NAME. Here is the way that actions are executed.
widget_object ACTION OTHER_ARGUMENTSHere widget_object is the same as WIDGET_NAME. With WIDGET_NAME, the context is that of a name of a potential object. With widget_object the context is that of an existing widget object. For example, here is a command to make a frame with desired size 10 x 10 centimeters. All widgets have a -width option. Some have a -height or -length option. These options require varying units of measurement as described above in Size. The widget command created with this widget is .frame. Here is an example of its use: .frame configure -width 15cwhich reconfigures the widget with a different width. Frame widgets appear as rectangles when they are visible at all. Often, frames exist to organize their slaves into something that can be properly packed in a larger widget. You may not see such a frame. When you see a frame, it is because of a border around it or because some of
it is showing with a distinctive color. All widgets can have borders of a few
specific kinds. But the borders can become invisible if the
One of the -relief alternatives will make a frame look like an unpushed button. Another will make a frame look like a pushed button. Indeed, it is through the -relief alternatives that buttons get their appearance. In fact, the distinctive appearance of many widgets is controlled by its borders. Possible values for -relief are: raised sunken flat groove ridgeFigure 12.3a shows ten frames each possible value of -relief is shown with two border widths.
The "flat" value is used when you do not want a visible border. A positive value for -borderwidth with the "flat" value for -relief will produce a widget whose border takes up screen real estate even though it appears not to be there. The frame widget has a default border width of 0. For most others, the default border width is positive. As an example, the following creates and packs a 5 centimeter square frame with a two pixel border that will make it look like a button. pack [frame .fake_button -relief raised -width 5c -height 5c]
The widget command that is created with a frame is as simple as can be. There are only two actions. These actions are available to all widgets created by built-in widget makers. They are:
One example of the configure action was shown above. Here is another applied to a widget named .p. .p configure -relief groove -borderwidth 2mThis will change the widget's relief to "groove" and make that groove 2 millimeters wide. If .p is mapped to the screen, the change will be visible almost immediately. (What actually happens is that a command to make the change goes immediately on the event loop. Usually, that means you see the change immediately on the screen.) For some widgets there are a few options that cannot be changed with the widget command's configure action they are fixed forevermore when the widget is created. If you have trouble changing an option, check your on-line manual to see if this is the reason. Notice that both the configure action and the cget action can be used to query option values. For example, this command, .p cget -widthwill tell you the desired width of the widget named .p and this command
.p configurewill give you a list of all .ps options and their values.
Remark
|
Author's Home Page |
|
Order from Amazon. |