⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 123.html

📁 Tcl 语言的入门级图书
💻 HTML
字号:
<HTML><TITLE>Widget Characteristics: Frames, the Archetypal, No-Frills Widgets</TITLE><BODY BGCOLOR="#FFF0E0" VLINK="#0FBD0F" TEXT="#101000" LINK="#0F0FDD">
<A NAME="top"><H1>Frames, the Archetypal, No-Frills Widgets</H1></A>


<P>  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:

<PRE>
<CITE>widget_type_name  WIDGET_NAME  ?OPTIONS?</CITE>
</PRE>

where <CITE>widget_type_name</CITE> 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.  <CITE>WIDGET_NAME</CITE> is the
pathname of the new widget object as described in 
<A HREF="11.2.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/11.2.html">The Tk Way of Thinking</A>.
<CITE>?OPTIONS?</CITE> is a sequence of zero or more option value pairs.  All built-in
widget makers return <CITE>WIDGET_NAME</CITE> and all of them create an object action
family whose name is <CITE>WIDGET_NAME</CITE>.  Here is the way that actions are
executed.
<P> 
<PRE>
<CITE>widget_object ACTION OTHER_ARGUMENTS</CITE>
</PRE>

Here <CITE>widget_object</CITE> is the same as <CITE>WIDGET_NAME</CITE>.  With
<CITE>WIDGET_NAME</CITE>, the context is that of a name of a potential object.
With <CITE>widget_object</CITE> the context is that of an existing widget object.

<P>  For example, here is a command to make a frame with desired size 
10  x 10
centimeters.

<PRE>
<NAME=#Cframe>frame</A> .frame -width 10c -height 10c
</PRE>

All widgets have a <TT>-width</TT> option.  Some have a <TT>-height</TT> or
<TT>-length</TT> option.  These options require varying units of measurement as
described above in 
<A HREF="12.2.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.2.html">Size</A>.  The widget command created with this
widget is <TT>.frame</TT>.  Here is an example of its use:

<PRE>
.frame configure -width 15c
</PRE>

which reconfigures the widget with a different width.

<P>  Frame widgets appear as rectangles &#150; 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.

<P>  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
<TT><NAME=#S12.3borderwidth>-borderwidth</A></TT> option is set to 0.  When nonzero, it is given a
value in screen distances as described in the previous section.  When there is
a border its appearance depends on the <TT><NAME=#S12.3relief>-relief</A></TT> option.

<P>   One of the <TT>-relief</TT> 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 <TT>-relief</TT> alternatives that buttons get their appearance.
In fact, the distinctive appearance of many widgets is controlled by its
borders.

<P>   Possible values for <TT>-relief</TT> are:

<PRE>
raised sunken flat groove ridge
</PRE>

Figure 12.3a shows ten frames &#150; each possible value of <TT>-relief</TT> is
shown with two border widths.  

<P><CENTER><TABLE BORDER>
<CAPTION><ADDR>Figure 12.3a: Possible widget borders.</ADDR></CAPTION>
<TR ALIGN=center><TD><IMG SRC="F12x3a.JPG" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Figs/F12x3a.JPG">
</TD></TR>
</TABLE></CENTER><P>

<P>  The "flat" value is used when you do not want a visible border. A positive
value for <TT>-borderwidth</TT> with the "flat" value for <TT>-relief</TT> will
produce a widget whose border takes up screen real estate even though it
appears not to be there.

<P>  The frame widget has a default border width of 0.  For most others, the 
default border width is positive.

<P>   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.

<PRE>
pack [frame .fake_button -relief raised -width 5c -height 5c]
</PRE>

<P> <P><A NAME="12.3a">
<STRONG>Exercise 12.3a</STRONG> </A><DL><DD>
  Reproduce Figure 12.3a.  Use 4 and 8 as the two
borderwidths for each frame.
<P>
<A HREF="12.8.html#Sol12.3a" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.3a">Solution</A></DL>


<P>  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:

<P><CENTER><TABLE BORDER><TR><TD><DL> 
<P> <DT><STRONG><PRE><CITE>widget_object</CITE> <NAME=#Wwdgtcnfgr>configure</A> <CITE>?OPTIONS?</CITE></PRE></STRONG><DD>
This changes the option values for an existing widget object.  <CITE>?OPTIONS?</CITE>
is a sequence of option/value pairs.  For example,

<PRE>
.frame configure -height 5c -width 5c
</PRE>

When <CITE>?OPTIONS?</CITE> is missing, the command returns a list of all option/value
pairs for the widget.

<P> <DT><STRONG><PRE><CITE>widget_object</CITE> <NAME=#Wwidgetcget>cget</A> <CITE>OPTION_NAME</CITE></PRE></STRONG><DD> This
returns the value for the named option.

When values measured in screen distances are returned, the actual unit
is always pixels &#150; even if the option was declared with inches, millimenters,
centimeters, or printer's points.
<P>  </DL></TD></TR></TABLE></CENTER></P>

<P>   One example of the  <TT>configure</TT> action was shown above.  Here is
another applied to a widget named <TT>.p</TT>.

<PRE>
.p configure -relief groove -borderwidth 2m
</PRE>

This will change the widget's relief to "groove" and make that groove 2
millimeters wide.  If <TT>.p</TT> 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.)

<P>   For some widgets there are a few options that cannot be changed with the
widget command's <TT>configure</TT> action &#150; 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.  

<P> Notice that both the <TT>configure</TT> action and the <TT>cget</TT> action can be used 
to query option values.  For example, this command,

<PRE>
.p cget -width 
</PRE>

will tell you the desired width of the widget named <TT>.p</TT> and this
command

<P> <PRE> 
.p configure
</PRE>

will give you a list of all <TT>.p</TT>s options and their values.


<P> <P><A NAME="12.3b">
<STRONG>Exercise 12.3b</STRONG> </A><DL><DD>
  This command

<PRE>
pack [frame .f -width 15m -height 15m -relief groove]
</PRE>

will produce a frame in your root window that has no visible groove.  Why?
How can the <TT>cget</TT> action verify your answer?  <P>
<A HREF="12.8.html#Sol12.3b" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.8.html#Sol12.3b">Solution</A></DL>



<P> <STRONG>Remark</STRONG> <DL><DD> The differences between widget types lie in their
default options and the event handlers associated with them.  They normally
look different because of the defaults.  They behave differently because of
the event handlers.  </DL>

<P> <!-- Linkbar -->
<P><CENTER><FONT SIZE=2><NOBR>
<STRONG>From</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/sbf/tcl/book/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/sbf/tcl/book/home.html'" tppabs="http://www.mapfree.com/sbf/tcl/book/home.html">Tcl/Tk For Programmers</A><WBR>
<STRONG>Previous</STRONG>
<A HREF="12.2.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.2.html">section</A><WBR>
<STRONG>Next</STRONG>
<A HREF="12.4.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.4.html">section</A><WBR>
<STRONG>All</STRONG>
<A HREF="12.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/12.html">sections</A><WBR>
<STRONG>Author</STRONG>
<A HREF="javascript:if(confirm('http://www.mapfree.com/mp/jaz/home.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mapfree.com/mp/jaz/home.html'" tppabs="http://www.mapfree.com/mp/jaz/home.html">J. A. Zimmer</A><WBR>
<STRONG>Copyright</STRONG>
<A HREF="copyright.html" tppabs="http://www.mapfree.com/sbf/tcl/book/select/Html/copyright.html">Notice</A><WBR>
<P>
<I>Jun 17, 1998</I>
 </NOBR></FONT></CENTER></BODY></HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -